sql-server - 如何在 Linq to Entities 中进行多个内部联接

标签 sql-server linq linq-to-entities

我已经搜索过SO,但找不到可行的解决方案。我只是想弄清楚 Linq to Entities 中多个内部联接的语法是什么。谢谢

最佳答案

乔恩的答案会起作用,但恕我直言 using join in LINQ to Entities is usually wrong ,因为它会重复模型中的代码。我可以在 L2E 中以更简单的方式重写 Jon 的查询:

var query = from customer in db.Customers
            from order in customer.Orders
            from product in order.Products
            from info in product.Info
            select new
            {
                customer.Name, 
                info.BriefDescription
            }

这大约是 50% 的打字和 0% 的重复代码。考虑到您的关系已在数据库和模型中定义。您是否真的想在编写的每个查询中再次重复它们,并在重构模型时中断查询?

关于sql-server - 如何在 Linq to Entities 中进行多个内部联接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1442967/

相关文章:

sql-server - Visual Studio 2019 - SSDT

c# - 从列表中选择 Lambda 或 linq

c# - 表达式 : a get-by-ID-selector when I have the Expression to get the ID?

c# - Linq to Entities 按周数分组

c# - 使用 Entity Framework 4 缓存 Linq to Entities 执行计划

asp.net - 对于 ASP.NET 应用程序,什么是 SQL Server 的良好替代品?

sql - SQL 注入(inject)后清理的最佳方法是什么?

c# - 将 byte[] 作为参数传递给 ReportViewer

c# - 动态或子句 Linq

c# - ASP.NET MVC 如何将 ModelState 错误转换为 json