简体   繁体   English

ADO.NET实体模型和LINQ

[英]ADO.NET Entity Model and LINQ

I'm using an ADO.NET Entity Model which I'm trying to query using LINQ. 我正在尝试使用LINQ查询的ADO.NET实体模型。

The problem I'm having is that I can't specify the where clause as I'd like. 我遇到的问题是我无法根据需要指定where子句。 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. 我猜想我可能没有在VS2010中正确设置我的实体模型。 Any advice you can offer would be gratefully received. 您能提供的任何建议将不胜感激。

Thanks, 谢谢,

Richard. 理查德。

LINQ to Objects supports queries like the following one. LINQ to Objects支持如下查询。 Try it in LINQ to Entities =) 尝试在LINQ to Entities =)中进行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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