将左外连接查询转换为实体框架查询
我有一个 sql 语句,我希望能够将其转换为 EF4。
它是一个简单的左外连接,看起来
SELECT *
FROM EntryDate
LEFT OUTER JOIN Member on Member.CardId = EntryDate.CardID
如何使用实体框架 4 来执行此操作?
I have a sql statement that I want to be able to convert into EF4.
Its a simple Left outer join that looks like
SELECT *
FROM EntryDate
LEFT OUTER JOIN Member on Member.CardId = EntryDate.CardID
how do I do this using the entity framework 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的模型中有映射的关系,您可以简单地使用导航属性,因为它们总是使用左连接:
我希望您没有这样的关系,因为
CardId
看起来不像的主键会员
或EntryDate
。如果您没有导航属性,则必须使用
这仅适用于 EFv4+,因为 EFv1 不支持
DefaultIfEmpty
。If there is relation mapped in your model you can simply use navigation properties because they always use left join:
I expect you don't have such relation because
CardId
doesn't look like primary key ofMember
orEntryDate
.If you don't have navigation properties you must use
This works only in EFv4+ because EFv1 didn't support
DefaultIfEmpty
.