c# - ADO.NET 实体模型和 LINQ

标签 c# linq entity-framework ado.net

我正在使用 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/

相关文章:

c# - 如何在 LINQ 连接中使用 AND

c# - 一对一识别关系的 Entity Framework Code First Fluent API 配置

C# Entity Framework : How to return a specified type after group. 加入?

c# - 从绑定(bind)列表中删除元素

c# - 类似 .Net string.CompareOrdinal 的 Linq 函数

c# - Entity Framework 核心中的postgres查询问题

c# - 需要一个非常定制的大型 Winforms 网格

c# - 摆脱不安全的代码,从字节编码 uint 数组?

c# - 如何将 ModelExpression 绑定(bind)到 ASP.NET Core 中的 ViewComponent?

c# - 在文本字段上进行关键字搜索的最佳方法是什么?