我正在使用 ADO.NET 实体模型,我正在尝试使用 LINQ 进行查询。
我遇到的问题是我无法按照我的意愿指定 where 子句。例如,考虑以下查询:
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
}
}
}
理想情况下,我希望它成为:
var accounts = from a in db.Accounts
where a.Identifiers.Identifier == identifier
select a;
我猜我可能没有在 VS2010 中正确设置实体模型。我们将不胜感激您提供的任何建议。
谢谢,
理查德。
最佳答案
LINQ to Objects 支持如下查询。在 LINQ to Entities 中试试 =)
var accounts = from a in db.Accounts
from i in a.Identifiers
where i.Identifier == identifier
select a;
关于c# - ADO.NET 实体模型和 LINQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2506591/