如何将此代码从 SQL 转换为 Linq
如何将下面的代码从 SQL 转换为 Linq
SELECT CF.CustomerProfileId,CF.Salutation,CF.Gender,CF.LastName,
CF.DateOfBirth,AD.Line1,AD.Line2,AD.Line3,AD.Line4,AD.Line5,
AD.Country,AD.ElectronicAddressDesc,NCIType.NationalCustomerIdentifierTypeDesc,
NCI.NationalCustomerIdentifier from CustomerProfile CF
left join Address AD on CF.CustomerProfileId = CF.CustomerProfileId
left join NationalCustomerIdentifiers NCI on CF.CustomerProfileId = NCI.CustomerProfileId
left join NationalCustomerIdentifierType NCIType on NCI.NationalCustomerIdentifierTypeId = NCIType.NationalCustomerIdentifierTypeId
where CF.CustomerProfileId = @CustomerProfileid and CF.Version = @Version
How can I convert this below code from SQL to Linq
SELECT CF.CustomerProfileId,CF.Salutation,CF.Gender,CF.LastName,
CF.DateOfBirth,AD.Line1,AD.Line2,AD.Line3,AD.Line4,AD.Line5,
AD.Country,AD.ElectronicAddressDesc,NCIType.NationalCustomerIdentifierTypeDesc,
NCI.NationalCustomerIdentifier from CustomerProfile CF
left join Address AD on CF.CustomerProfileId = CF.CustomerProfileId
left join NationalCustomerIdentifiers NCI on CF.CustomerProfileId = NCI.CustomerProfileId
left join NationalCustomerIdentifierType NCIType on NCI.NationalCustomerIdentifierTypeId = NCIType.NationalCustomerIdentifierTypeId
where CF.CustomerProfileId = @CustomerProfileid and CF.Version = @Version
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 LINQ 中进行多次左连接。这是可能的,但看起来不太好(linq 在处理内部连接以外的连接时不是很舒服)。
这是 linq 中左连接的 microsoft 示例 它只连接两个表但你可以延长它。如果您不喜欢结果的外观 - 则创建一个视图或存储过程。
You need to make several left joins in LINQ. This is possible though will look not very good (linq is not very comfortable when dealing with joins other than inner).
Here is a microsoft example of left join in linq It only joins two tables but you can extend it. And if you don't like how the result looks - than make a view or an sproc.