我创建了一个控制台应用程序来从"Dynamics CRM 2016"中提取信息。我使用XrmServiceContext
来获取数据,并且我能够从不同的实体中提取信息,但在通过特定属性获取EmailSet
时会遇到问题。
我的代码:
//This works
var test= context.EmailSet.FirstOrDefault(e => e.RegardingObjectId.Id == Guid);
//This doesn't work
var test= context.EmailSet.FirstOrDefault(e => e.RegardingObjectId.Name == "somename");
这行抛出了一个异常:
"Invalid 'where' condition. An entity member is invoking an invalid property or method."
问题:是否可以通过RegardingObjectId.Name
查询EmailSet
?
我看不出这处房产有什么特别之处,希望有人能帮我。
不幸的是,Linq-To-CRM有一些缺点,但您可以使用更灵活的fetchxml。
var results = service.RetrieveMultiple(
new FetchExpression(
string.Format("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='email'>" +
"<attribute name='subject' />" +
"<filter type='and'>" +
"<condition attribute='regardingobjectidname' operator='eq' value='{0}' />" +
" </filter>" +
"</entity>" +
"</fetch>", "foobar")));
var emails = results == null
? new List<Email>()
: results.Entities.Cast<Email>();