Use Matadata file to add attributes for properties in Ria service
2010-11-05 11:18
316 查看
When you are using Ria service. You will have to create your own ADO.net entity modal. In this case, the designer will generate a lot code for you. But in the generated code, you want to add some useful attributes for some column. such as [Include] attribute, it will allow you to get the navigation property and transfer to your silverlight client. Without this attribute, you will not getting data for this navigation property at your client.
Of courese, you can also add the attribut directly on the property as following, it will work for sure.
But here is a problem, when you want to update your entity modal from database, you will have to use "Update modal from database". after doing this, all your modifications will be removed. you have to readd them once. if there are a lot of code, it is disaster for the project.
Luckily, i found we can create our own matadata class for this situation. Just add the following code in your project, it will work.
And this matadata file won't be overwritten by "Updata modal from database".
Of courese, you can also add the attribut directly on the property as following, it will work for sure.
/// <summary> /// No Metadata Documentation available. /// </summary> [XmlIgnoreAttribute()] [SoapIgnoreAttribute()] [DataMemberAttribute()] [EdmRelationshipNavigationPropertyAttribute("MyTradeModel", "RoleUser", "Role")] [Include] public Role Role { get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Role>("MyTradeModel.RoleUser", "Role").Value; } set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Role>("MyTradeModel.RoleUser", "Role").Value = value; } }
But here is a problem, when you want to update your entity modal from database, you will have to use "Update modal from database". after doing this, all your modifications will be removed. you have to readd them once. if there are a lot of code, it is disaster for the project.
Luckily, i found we can create our own matadata class for this situation. Just add the following code in your project, it will work.
[MetadataTypeAttribute(typeof(User.UserMetadata))] public partial class User { internal sealed class UserMetadata { [Include] public Role Role { get; set; } } }
And this matadata file won't be overwritten by "Updata modal from database".
相关文章推荐
- 94.You plan to move data from a flat file to a table in your database. You decide to use SQL*Loader
- How to save data in ASCII format in ADS for use in MATLAB
- The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the ser
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- How to use the ZooKeeper driver for ServiceGroup in OpenStack Nova
- how to use Properties and File to Save Data
- Add a file to a Document Library and update metadata properties in a single method添加文档的方法
- Re: How to use values of properties file in selenium code - msg#02103
- How to use HTML-5 data-* attributes in ASP.NET MVC
- Putting Spark to Use: Fast In-Memory Computing for Your Big Data Applications
- Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfile or
- [Tips] How to Add New field into Shapefile attribute table in ArcGIS ?
- How to make a USB stick use ISO image file in debian
- 执行打的maven jar包时出现“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”
- How to add the selinux policy access for the new created linux file node.
- Programmatically add credentials to an ASMX Web Service that is password protected in C#
- Exporting Mailbox Data to a PST File in Exchange 2007 SP1(如何导出邮箱数据为PST文件)
- How to use insert or retrieve data by using Core Data in iOS
- How to write own add-in for SSMS 2012 (Final release version)
- [PostgreSQL] Use Foreign Keys to Ensure Data Integrity in Postgres