简体   繁体   中英

ADO.NET Entity Model and LINQ

I'm using an ADO.NET Entity Model which I'm trying to query using LINQ.

The problem I'm having is that I can't specify the where clause as I'd like. For instance, consider the following query:

AccountsDM db = new AccountsDM(ConfigurationManager.ConnectionStrings["PrimaryEF"].ConnectionString);
var accounts = from a in db.Accounts
               select a;
foreach (var account in accounts)
{
    foreach (var ident in account.Identifiers)
    {
        if (ident.Identifier == identifier)
        {
            // ident.Identifier is what I'd like to be filtering in the WHERE clause below
        }
    }
}

Ideally, I'd like that to become:

var accounts = from a in db.Accounts
               where a.Identifiers.Identifier == identifier
               select a;

I'm guessing I've probably not set up my Entity Model correctly in VS2010. Any advice you can offer would be gratefully received.

Thanks,

Richard.

LINQ to Objects supports queries like the following one. Try it in LINQ to Entities =)

var accounts = from a in db.Accounts
                 from i in a.Identifiers
                 where i.Identifier == identifier 
               select a; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM