假设A作为对象模型具有属性ID(int)和Status(Bool),B作为对象模型也具有ID(int)和Status(Bool)
我希望从A的数据中获取数据。 如果它是一个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 .....)我不知道如何申请“ 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)
And I want get data from A filtered by it's property. 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..
var c = A.Where(a=>a.Status==True && a.ID .....) I don't know how to apply "in" here
I'm really new to use C# Entity Framework.
最满意答案
如果A和B有一些关系并且由名为AB的导航属性表示,那么查询可以是这样的简单:
var c = A.Where(a=>a.Status && a.AB.Status);如果他们没有任何关系,那么你也可以像这样直接查询(虽然性能不如上面那么好):
var c = A.Where(a=>a.Status && B.Where(b=>b.Status).Any(b=>b.ID == a.ID))If A and B has some relationship and is represented by a navigation property named AB, then the query can be simple like this:
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))更多推荐
发布评论