简体   繁体   English

在C#Entity-Framework中过滤对象模型的数据

[英]Filter Data of Object Model in C# Entity-Framework

Assume A as object model that have property ID(int) and Status(Bool) and B as object model also have ID(int) and Status(Bool) 假设A作为对象模型具有属性ID(int)和Status(Bool),B作为对象模型也具有ID(int)和Status(Bool)

And I want get data from A filtered by it's property. 我希望从A的数据中获取数据。 if it an sql query like "select * from A where A.Status=True and A.ID in (Select ID from B Where B.Status=True) , I don't now how to make var C = that query.. 如果是一个sql查询,比如"select * from A where A.Status=True and A.ID in (Select ID from B Where B.Status=True) ,我现在不知道怎么做var C =那个查询..

var c = A.Where(a=>a.Status==True && a.ID .....) I don't know how to apply " in " here var c = A.Where(a=>a.Status==True && a.ID .....)我不知道如何申请“ in ”这里

I'm really new to use C# Entity Framework. 我真的很想使用C#Entity Framework。

If A and B has some relationship and is represented by a navigation property named AB, then the query can be simple like this: 如果A和B有一些关系,并由名为AB的导航属性表示,那么查询可以很简单,如下所示:

var c = A.Where(a=>a.Status && a.AB.Status);

If they don't have any relationship, then you can also query directly like this (although the performance won't be as good as the above): 如果他们没有任何关系,那么你也可以像这样直接查询(虽然性能不如上面那样):

var c = A.Where(a=>a.Status && B.Where(b=>b.Status).Any(b=>b.ID == a.ID))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM