English 中文(简体)
Using Entity Framework generated classes in Business Logic Layer
原标题:

I have a ASP.net (C#) project that is using a three layer architecture. I started to use Entity Framework in my DAL and the question is to what extent classes generated by Entity Framework can be used in the Business Logic Layer?

It is a good idea to use them directly or should i create my own business objects and map to them from Entity Framework(db->O/RM->BOs)?

最佳回答

In my opinion, the EF objects would be mapped to yours. This has a higher development cost, but gives the added benefit of persistence ignorance and decoupling. This decoupling can translate to significant agility and real world savings in the long-run, should the business need to switch to a different persistence solution. Without the decoupling, the EF objects can become deeply embedded in the BLL and even presentation layers, requiring a huge refactoring. In such a case, the business might not even consider switching persistence solutions, which could cause the business to be less competitive.

The decision to reap this benefit at the higher development cost depends on the amount of risk the business is willing to take. I suggest you consult with the project commissioners and use your best judgement to interpret their strategic objectives in a technical way.

问题回答

It should be reasonable enough to use the generated classes as your Business Objects. The generated classes are partial so you can easily extend them as you please. Sometimes I find it a nicer option however to use interfaces.

I have just started on EF 2.0 (in .Net 4.0 beta 2) and it has the facility to use POCO clases as EF entities. i.e. You can now use persistence ignorant classes in EF 2.
I think this is not fully ready yet, as I couldn t follow the presentation from PDC 2009 when working in Visual Studio 2010 beta 2 but keep a watch out for this at ADO.Net team blog.

You may want to look at the Persistence Ignorance (POCO) Adapter for Entity Framework. This is an open-source project from a member of the EF team that brings POCO support to EF 1.0. EF 4.0 will have POCO support out-of-the-box, but this project serves as a stop-gap measure until .NET 4.0 drops in 2010.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签