Richard
Richard

Reputation: 1252

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.

Upvotes: 2

Views: 318

Answers (1)

Jens
Jens

Reputation: 25563

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; 

Upvotes: 1

Related Questions