views:

44

answers:

1

Hi all

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.

+1  A: 

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; 
Jens
That's exactly what I was after - spot on, thank you!
Richard