在一次数据库中获取不相关的实体

kat*_*thy 5 entity-framework

我有3个实体彼此不相关,我想在一次数据库中获取所有这些实体我该怎么办?

谢谢

Rog*_*son 0

你可以这样做:

 var result = from foo in ctx.Foos
              from bar in ctx.Bars
              where foo.id == xxx && bar.id == yyy
              select new { Foo = foo, Bar = bar};
Run Code Online (Sandbox Code Playgroud)

这将在同一查询中为您获取特定的 foo 和 bar。不过,这会生成一些相当低效的 SQL,所以我不推荐它。