|
Starting with Visual Studio 2010, when you generate a model from an existing database, the ADO.NET Entity Data Model Designer (Entity Designer) creates scalar properties on entity types that correspond to foreign key columns in the database.
By default, the Entity Designer also generates navigation properties on entity types that can be used to create and modify relationships.
The problem is that this auto generated navigation property are marked with DataMemberAttribute and thus, exposed to the WCF client.
In case you use LazyLoading feature of entity Framework, then data contract serializer will try to serialize WHOLE graph of the objects, resulting in huge amount of data to be transferred to the client.
If you disable LazyLoading, this will reduce the amount of data being transferred to the client. But in this case navigation properties will be still present on the client side, confusing it (If navigation property contains no data, client will not know if there is no data in the DB or property was not loaded by the WCF service).
Therefore, i think in some cases it is really good to exclude Entity Framework Navigation Properties from WCF service contract.
Doing so will allow you to continue to use LazyLoading (i like this) in your WCF service implementation, while clearing client-side object definitions.
There are several possible ways to achieve it. I found the following one to be just right work me
Customizing Entity Classes in VS 2010.
This is the link to the original article: http://blogs.msdn.com/b/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx
Following this article, you need to do:
1. Rght-click on the Entity Framework designer, select "Add code generation item"
2. From Installed templates (Code) select ADO.NET EntityObject Generator And specify the name of the tt file.
3. In properties of the edmx file clear "Custom Tool" property.
4. Modify the appeared tt file to remove DataMemberAttribute from Navigation property code generation.
That's it. Hope it helps. |