C#Entity

编程入门 行业动态 更新时间:2024-10-28 00:16:27
C#Entity-Framework中对象模型的过滤数据(Filter Data of Object Model in C# Entity-Framework)

假设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))

更多推荐

本文发布于:2023-08-01 11:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1357897.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Entity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!