我有两个自定义实体 Product 和 ProductType,它们以多对一的关系链接在一起。Product 有一个 ProductType 的查找字段。
我正在尝试编写一个查询来获取价格超过 100 的 Type1 产品和价格低于 100 的 Type2 产品。
这是我在 SQL 中的做法:
select *
from Product P
inner join ProductType T on T.Id = P.TypeId
where (T.Code = 'Type1' and P.Price >= 100)
or (T.Code = 'Type2' and P.Price < 100)
我想不出一种方法来构建一个 QueryExpression 来做到这一点。我知道我可以用两个查询来做到这一点,但我想尽量减少到服务器的往返。
有没有办法只在一个操作中执行该查询?
谢谢!