linq包括内在加入ISN´ t工作
我一直在尝试运行查询,
dbContext.Model.Include(x => x.ListItems);
但是我总是得到一个左联接,我需要一个内在的加入。我尝试将其添加到我的上下文类中:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LogTL>()
.HasOne(p => p.ListaFluxos)
.WithMany()
.IsRequired(); ;
}
但是仍然没有成功。
I´ve been trying to run the query
dbContext.Model.Include(x => x.ListItems);
But I always get a Left Join and i need a Inner Join. I tried adding this to my context class:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LogTL>()
.HasOne(p => p.ListaFluxos)
.WithMany()
.IsRequired(); ;
}
but still no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么需要内部加入? EF默认情况下将使用左联接来容纳可能没有ListItem的模型。
如果您只需要具有ListItems的模型,则可以使用以下方式查询:
尽管这可能不会导致EF产生内部联接。最后,我想重要的是为什么您觉得您需要内部连接,而与左连接在一起。如果关注性能,通常可以通过解决索引和利用诸如投影之类的内容来优化查询运行之类的内容来满足。相反,如果您想通过EF复制一个非常具体的查询(通常更复杂),则更好的方法可以是利用数据库中的视图之类的东西,并将实体模型映射到结果。
Why do you need an Inner Join? EF by default will use a Left Join to accommodate Models that may not have ListItems.
If you want only Models that have ListItems then you can query that with:
Though that may not result in EF producing an Inner Join. In the end I guess what matters is why you feel you need an Inner Join vs. a Left Join. If it is a concern around performance, that is generally better met by addressing indexing and leveraging things like projection to optimize the queries run. If instead there is a very specific (and typically more complex) query you want to reproduce via EF, a better approach can be to leverage something like a View in the database and map an entity model(s) to the result.