在 LINQ 查询中设置值
我有一个项目,我需要从一个实体加载结果 选择结果,然后使用这些结果加载另外 2 个实体,并从中选择稍后将返回的数据。
是否可以从 3 个存储库构建 LINQ 查询 ? 请给我一些代码示例或给我指向链接...我找不到
这只是我询问是否可能的涂鸦:
ARepository rep = new AReository();
BRepository rep = new BReository();
var Q1= rep.GetAllView1()
.Select(o=>new {
X=o.data.aaa,
Y=o.data.bbb,
....
var Q2= rep.GetAllView2()
.Where(x => x.bata.ss == X
var Q3= rep.GetAllView3()
.Where(x => x.cata.ff== Y
I have a project where i need to load results from one entity
select results and than with those results to load another 2 entities and select from them data wich will be return later.
is it possiable to build LINQ Query from 3 repositories
?
please give me some code examples or point me to links...i cannot find how
this is just a doodle of something that i ask if it possiable:
ARepository rep = new AReository();
BRepository rep = new BReository();
var Q1= rep.GetAllView1()
.Select(o=>new {
X=o.data.aaa,
Y=o.data.bbb,
....
var Q2= rep.GetAllView2()
.Where(x => x.bata.ss == X
var Q3= rep.GetAllView3()
.Where(x => x.cata.ff== Y
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要使用导航属性才能提高效率。您所展示的内容是可能的,但是当您不需要它们时,您很可能最终会取回所有实体。从您的示例来看,您有三个实体:
View1
View2
与 View1.aaa View3
最简单的方法是在数据库中定义这些键,但您可以在实体框架设计器中定义它们。一旦你建立了关系模型,事情就变得非常简单......
所以 View1 实体可能看起来像这样:
一旦你有了这样一个实体,下面的代码就可以工作:
此时你已经有了一个 View1 对象的集合,所有对象都有 2 个对象属性及其关联的 View2 和 View3 实体。
I think you would need to use navigation properties for this to be in any way efficient. What you show is possible, but you are very likely to end up getting all the entities back when you do not need them. It looks from your example that you have three entities:
View1
View2
View3
The easiest is to have these keys defined in the database but you can define them in the entity framework designer. Once you have the relationships modelled, it makes things really easy...
So the View1 entitiy could look like this:
Once you have such an entity the following code would work:
By this point you have a collection of View1 objects, all with 2 properties with their associated View2 and View3 entities.