如何将 SQL 转录为 LINQ
select * form autor
inner join (carte inner join carte_autor using id_carte)
using id_autor
group by id_autor;
我如何使用 LINQ 编写此代码?
谢谢。
select * form autor
inner join (carte inner join carte_autor using id_carte)
using id_autor
group by id_autor;
How can I write this using LINQ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用设计器创建 DataContext 并正确定义了外键,则这些外键应显示为实体类(Entity 或 EntitySet)上的属性,具体取决于它是 1-1 还是 1-many。如果没有分配外键,您还可以在设计器中定义关系。
否则,您可以执行以下操作:
请注意,这将选择匿名类型。我发现通常在进行联接时,我最终会选择属性的子集为匿名(或有时命名)类型,而不是构成联接的实际实体。这就是为什么我以这种方式展示它。当然,您可以保留完整的对象并相应地调整选择/分组依据。
If you're creating the DataContext using the designer and have foreign keys defined appropriately, these should show up as properties on your entity classes, either Entity or EntitySet, depending on whether it is 1-1 or 1-many. You can also define the relationships in the designer if you don't have foreign keys assigned.
Otherwise, you can do something like:
Note that this will select out an anonymous type. I find that generally when doing a join I end up selecting a subset of properties into an anonymous (or sometimes named) type, not the actual entities comprising the join. That's why I've shown it this way. You can, of course, keep the full objects around and adjust the select/groupby accordingly.