开发者

Entity Framework 4: Encapsulate navigation properties in business objects

I want to encapsulate all EF entit开发者_Python百科ies in business objects. The EF entity "Investment" will have a "BoInvestment" business object that holds the entity internal and routes all properties. For navigation properties that is a challenge. Let's say my "Investment" has "Reports" has an EntityCollection which is lazy loaded. My business object "BoInvestment" would need this "Reports" as "BoReports" since "Report" is also encapsulated in a business object. If I would just return an "IList" it would mean that all Reports are always loaded into memory. I would loose the EF advantage that EntityCollection is only a Querable until it is materialized.

Any Ideas :)


The idea is using entities directly as business objects instead of wrapping the into a new object layer. It will work much better if you use POCOs instead of Entity objects. If you want to stick with your current architecture check Lazy<T> - msdn. That could be a way to implement your navigation properties on business objects.


Why not use an IQueryable? this way you would still have the advantage of query composition and lazy loading.

Another idea would be to take advantage of the fact that the entity objects generated by EF are in fact partial classes that you can extend to include your BO functionality

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜