开发者

how can i query an already loaded data in EF?

开发者 https://www.devze.com 2022-12-21 19:22 出处:网络
I have an object Customer with a 1-n relationship to Addresses. I want to be a开发者_如何转开发ble to take the first address. So i create a method:

I have an object Customer with a 1-n relationship to Addresses.

I want to be a开发者_如何转开发ble to take the first address. So i create a method:

public Address firstAddress
{
     get
     {
         var f=from d in this.Addresses
               select d;
         return f;
     }
} 

I get the following error :

Error 5 Impossible to find an implementation ofsource 'System.Data.Objects.DataClasses.EntityCollection'. 'Select' introuvable. Une référence à 'System.Core.dll' ou une directive using pour 'System.Linq' est-elle manquante ?

I do not undertand why i can't query the collection of addresses... Thanks John


Well, the error message tells you where to start looking, presuming you can read French. :) Make sure your app has a reference to the System.Core assembly and your code file has using System.Linq; at the top.

Also, I think the query is wrong. I'm presuming that this.Addresses is an enumeration of the type Address. In this case you'd need:

public Address firstAddress
{
     get
     {
         var f=(from d in this.Addresses
                select d).FirstOrDefault();
         return f;
     }
} 
0

精彩评论

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