使用Dynamics CRM 4.0执行复杂的查询 [英] Performing complex query with Dynamics CRM 4.0
问题描述
我有两个自定义实体Product和ProductType,它们以多对一关系链接在一起。产品具有对ProductType的查找字段。
I have two custom entites, Product and ProductType, linked together in many-to-one relationship. Product has a lookup field to ProductType.
我正在尝试编写查询以获取价格超过100的Type1产品和价格低于100的Type2产品
I'm trying to write a query to fetch Type1 products with a price over 100, and Type2 products with a price lower than 100.
这是我在SQL中的处理方式:
Here's how I would do it in 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的方法来精确地做到这一点。我知道我可以用两个查询来做到这一点,但我想将往返服务器的次数降到最低。
I can't figure out a way to build a QueryExpression to do exactly that. I know I could do it with two queries, but I'd like to minimize roundtrips to the server.
有没有一种方法可以只执行一次操作?
Is there a way to perform that query in only one operation ?
谢谢!
推荐答案
不幸的是,不,不可能用QueryExpression或FetchXML做到这一点。至少不是Dynamics CRM 4所没有。希望它们在版本5(2010年下半年)中包含此功能。
Unfortunately, no, it is not possible to do that with a QueryExpression or FetchXML. At least, not with Dynamics CRM 4. Let's hope they include this feature in version 5 (2nd half 2010)
这篇关于使用Dynamics CRM 4.0执行复杂的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!