开发者

Entity Framework projections

开发者 https://www.devze.com 2023-02-10 05:18 出处:网络
We are investigating the Entity Framework to see if it will meet our particular needs.Here is the scenario I am interested in:

We are investigating the Entity Framework to see if it will meet our particular needs. Here is the scenario I am interested in:

I have a large table (let's call it VeryWideRecord) which has many columns, and it has a corresponding business object (it's also called Ve开发者_运维知识库ryWideRecord). I would like to be able to query my database for a VeryWideRecord business object, but only have values for certain columns returned by the underlying SQL. Can I do this with the Entity Framework?

I am uncertain as to whether this could be done with the Entity Framework's table splitting feature, because the application needs to be able (at runtime) to change the columns that are requested. The reason for this is that we are trying to minimize the amount of information that is going across the wire.

I see how this could be done using NHibernate (example), but how can I do this with the Entity Framework?


It looks like you can achieve what you are looking for with entity SQL. Following is the link:

http://msdn.microsoft.com/en-us/library/bb738683.aspx


Something like this (in VB.NET:

Dim pl As New List(Of VeryWideRecord)(
     (From p In db.VeryWideRecords 
      Select New With {.RecID = p.RecID}
     ).ToList().Select(
       Function(r)
         Return New VeryWideRecord With {.RecID = r.RecID}
       End Function))

With this you have some compiletime checking. But if you want to do this really dynamically, eSQL is maybe more suitable. And also, it's not really the Entity Framework, but the lambda expression who does the trick.

0

精彩评论

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

关注公众号