ASP.NET hierarchical application – sharing entity data model between layers

How can I share the automatically generated entity data model (generated object class) in all layers of my C# Web application, while granting query access only in the data layer? This uses the typical 3-layer method: data, business, presentation.

My data layer returns IEnumerable< T> to my business layer, but I cannot return type T to the presentation layer, Because I don’t want the presentation layer to be aware of the existence of the data layer-this is where Entity Framework automatically generates my classes.

It is recommended to use a separate layer that only contains the data model, but I am not sure how to provide it from Entity Framework Separate the data model from the query function.

If you use POCO entities (.NET 4), then It’s easy (or at least easier). Is it possible?

You can create DTOs like Ben said, but you are basically reducing and copying each entity. If you want, EF2 will create “dumb” entities and dynamically add change tracking , Lazy loading, etc.

Otherwise the answer is that you can’t do it. If the entities depend on the Entity Framework, then you can’t use them throughout the application without dragging that dependency. In this case Below, you must use DTO. This is a third-party option for EF 1 or EF 2 without a POCO entity.
http://automapper.codeplex.com/

Edit: Here are some useful ones Link to learn more about all of this

>General MS Guide:
http://msdn.microsoft.com/en-us/library/bb738470.aspx
> POCO Template:
http://blogs.msdn.com/adonet/pages/walkthrough-poco-template-for-the-entity-framework.aspx
> POCO template, including how to
go to a separate Project:
http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx
> POCO proxy:
http: //blogs.msdn.com/adonet/archive/2009/12/22/poco-proxies-part-1.aspx
>How to split the model:
http://blogs.msdn.com/adonet /archive/2008/11/25/working-with-large-models-in-entity-framework-part-2.aspx
>employee tracker sample application
(layers, unit test, simulation,
Repository, etc.):
http://code.msdn.microsoft.com/ef4/Release/ProjectReleases.aspx?ReleaseId=4279

How Share the automatically generated entity data model (generated object class) in all layers of my C# web application, while granting query access only in the data layer? This uses the typical 3-layer method: data, business, presentation.

My data layer returns IEnumerable< T> to my business layer, but I cannot return type T to the presentation layer, Because I don’t want the presentation layer to be aware of the existence of the data layer-this is where Entity Framework automatically generates my classes.

It is recommended to use a separate layer that only contains the data model, but I am not sure how to provide it from Entity Framework Separate the data model from the query function.

If you use POCO entities (.NET 4), then this is easy (or at least easier). This has is it possible?

You can create DTOs like Ben said, but you are basically reducing and copying each entity. If you want, EF2 will create “dumb” entities and dynamically add change tracking , Lazy loading, etc.

Otherwise the answer is that you can’t do it. If the entities depend on the Entity Framework, then you can’t use them throughout the application without dragging that dependency. In this case Below, you must use DTO. This is a third-party option for EF 1 or EF 2 without a POCO entity.
http://automapper.codeplex.com/

Edit: Here are some useful ones Link to learn more about all of this

>General MS Guide:
http://msdn.microsoft.com/en-us/library/bb738470.aspx
> POCO Template:
http://blogs.msdn.com/adonet/pages/walkthrough-poco-template-for-the-entity-framework.aspx
> POCO template, including how to
go to a separate Project:
http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx
> POCO proxy:
http: //blogs.msdn.com/adonet/archive/2009/12/22/poco-proxies-part-1.aspx
>How to split the model:
http://blogs.msdn.com/adonet /archive/2008/11/25/working-with-large-models-in-entity-framework-part-2.aspx
>employee tracker sample application
(layers, unit test, simulation,
Repository, etc.):
http://code.msdn.microsoft.com/ef4/Release/ProjectReleases.aspx?ReleaseId=4279

Leave a Comment

Your email address will not be published.