- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
SO 上已经有很多关于 Linq 中的左连接的问题,我看过的问题都使用 join
关键字来实现所需的结果。
这对我来说没有意义。假设我有表 Customer
和 Invoice
,它们由 Invoice
上的外键 CustomerID
链接。现在我想运行一份包含客户信息以及所有发票的报告。 SQL 将是:
select c.*, i.*
from Customer c
left join Invoice i on c.ID = i.CustomerID
根据我在 SO 上看到的答案,人们大多建议:
var q = from c in Customers
join i in Invoices.DefaultIfEmpty() on c.ID equals i.CustomerID
select new { c, i };
我真的不明白这怎么可能是唯一的方法。 Customer
和 Invoice
之间的关系已经由 LinqToSQL 类定义;为什么我必须为 join
子句重复它?如果我想要一个内部联接,它会简单地是:
var q = from c in Customers
from i in c.Invoices
select new { c, i };
不指定连接字段!
我试过:
var q = from c in Customers
from i in c.Invoices.DefaultIfEmpty()
select new { c, i };
但这只给了我与内部连接相同的结果。
没有更好的方法吗?
最佳答案
虽然关系已经定义(在数据库和 .dbml 标记中),运行时无法自动确定它是否应该使用该关系。
如果对象模型中有两个关系(Person 有 Parents 和 Children,两者都与其他 Person 实例有关系)怎么办?虽然案例可能是特殊案例,但这会使系统更加复杂(因此会有更多错误)。请记住,在 SQL 中您会重复关系的规范。
请记住,索引和键是实现细节,而不是构成关系模型基础的关系代数的一部分。
如果你想要一个 LEFT OUTER JOIN 那么你需要使用“into
”:
from c in Customers
join i in Invoices on i.CustomerId equals c.CustomerId into inv
...
inv 的类型为 IEnumerable<Invoivce>
,可能没有实例。
关于c# - 离开加入 Linq?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1092562/
var newRight; if(either.isRight()) { newRight = either.getOrElse(() => throw UnimplementedError())
我正在做一个登录字段。它由 UITextfields 和一个弹出选择器 Controller 的按钮组成。单击按钮以显示按钮弹出时,我想删除/保留/取消编辑文本字段。 我试过: [发件人resignF
我试图在用户关闭选项卡或转到另一个选项卡(如 facebook、gmail、GoDaddy 和其他选项卡)之前显示确认弹窗。 我的代码适用于 Firefox,但不适用于 chrome、safari 等
我无法退出代码中的 While 循环和方法。用户可以选择输入 1 或 2 和 0 来取消(离开菜单和方法)。但是就像现在的代码一样,我猜 Switch 中的默认选项会阻止它离开 While 循环!?我
所以我目前正在学习这个关于 PHP 表单的教程,并且我把它放到了这个页面的底部,它说到目前为止要测试表单,http://www.webreference.com/programming/php/sea
我正在开发一个可以让用户登录 2 个 xmpprooms 的应用程序,但同时只能登录 2 个,所以如果他想连接到另一个,我必须断开他与前一个的连接并连接到下一个。使用此代码: 这是我离开房间的方式:
我目前正在 React 应用程序中使用我的网络摄像头拍照。然而,当我离开组件时,绿灯继续亮着,我似乎无法关闭我的网络摄像头。这是我用来使用网络摄像头的代码。 navigator.webkitGet
实际到达很简单,标签进入接收器天线范围,但是偏离是造成问题的原因。 首先,我们了解一些有关设置的信息。 标签: 它们以433Mhz的速度工作,每1.5秒钟发送一次“心跳”,移动时进入传输突发模式,这种
这是我的第二个问题(已经回答):Creating SharedPreferences object inside Fragment . 在弄清楚如何在静态 Fragment 类中创建 SharedPr
我需要离开 Firebase 中的一个项目,但我没有选择离开该项目,因为我没有该项目的所有权。我是该项目的成员,需要离开该项目,因为该项目的开发已在几个月前停止 有什么选择可以做到这一点吗?我还需要从
我希望在以下情况下触发我的 javascript: 当打开多个 IE 选项卡时,当前 IE 选项卡将被切换。 当前 IE 选项卡关闭时。 我不希望我的 JS 代码被页内弹出对话框触发。 当整个 IE
我在 socket.io wiki 上查看如何使用房间,但加入和离开不起作用,我想知道他们是否可能更改了一些内容但没有机会更新 wiki? socket.join("room-"+data.meid)
在此 Activity 中我使用振动,因此由用户选择按照振动节奏移动的球,但是当我想向后返回屏幕时,即返回到MainActivity,应用程序继续振动而不停止。这是我的代码,我已经尝试了所有方法,但无
我正在构建一个用于学习 SwiftUI 的小型待办事项应用程序,我可以在 CoreData 中创建一个任务列表并将它们标记为完成,这会将 isComplete 设置为 true 并将图像从空圆圈更改为
我在 if 语句中有一个 if 语句。 如果第二个if语句中的条件返回false,我要转到第一个else因为它会自动设置我的验证控件。 希望你明白 if (page.isvalid() ) {
我正在尝试找到一种方法,让我的变量在应用程序的整个生命周期中保持不变。我设计该应用程序的方式是用户单击类(class)并提交成绩。我想要的是应用程序在 Activity 结束后存储成绩。当用户退出屏幕
首先你应该知道,允许玩家玩的区域是一个正方形,即320x320,位于屏幕中央。这个 320x320 的正方形是一个 5x5 的网格 [每个图 block 64x64],并且玩家始终位于网格图 bloc
我的应用程序在离开 UIViewController 时崩溃并出现以下错误。 [FeedSingleViewCell retain]: message sent to deallocated inst
使用此代码允许媒体播放器在全屏时横向旋转(应用程序不支持): // handle orientation for the device func application (_ application:
好的。查看了可能的答案,但我在这里没有看到我的问题。 我有一个相当标准的 GCD 重复计时器: class RepeatingGCDTimer { /// This holds our cur
我是一名优秀的程序员,十分优秀!