我构建了一个简单的查询来返回用户团队成员资格(N:N关系)。这适用于所有用户,但是当我添加一个where子句来限制特定用户时,它会抛出一个错误异常(参见下面的stacktrace)。
奇怪的是,这适用于“Where Users.FullName.StartsWith(”Alex“)”。 Dynamics CRM SDK LINQ实现是否不支持where子句中的Guids?
有什么建议吗?
示例代码
using (var service = new OrganizationService("Xrm"))
{
using (var xrm = new XrmServiceContext(service))
{
var AlexUser = xrm.SystemUserSet.Where(p => p.FullName.StartsWith("Alex")).First();
var AlexID = AlexUser.Id;
var Test =
from Users in xrm.SystemUserSet
join TeamMemberships in xrm.TeamMembershipSet on Users.Id equals TeamMemberships.SystemUserId
join Teams in xrm.TeamSet on TeamMemberships.TeamId equals Teams.Id
where Users.Id == AlexID // <-- problematic where clause
orderby Users.FullName
select new
{
FullName = Users.FullName,
UserID = Users.Id,
TeamName = Teams.Name
};
var Test1 = Test.ToList();
}
}
堆栈跟踪:
服务器堆栈跟踪:at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc&amp; rpc)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局,TimeSpan超时)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局) System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)
在[0]处重新抛出异常:at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgData,Int32类型)at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest 请求) Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest 请求) Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest 请求) Microsoft.Xrm.Client.Services.OrganizationService&LT;&GT; C_ DisplayClass19.b _18(IOrganizationService s)at Microsoft.Xrm.Client.Services.OrganizationService.InnerOrganizationService.UsingService [TResult](Func
2 action) at Microsoft.Xrm.Client.Services.OrganizationService.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Linq.QueryProvider.RetrieveEntityCollection(OrganizationRequest request, NavigationSource source) at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute(QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List
1 linkLookups, 字符串和放大器; pagingCookie,Boolean&amp; moreRecords)at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute [TElement](QueryExpression qe,Boolean throwIfSequenceIsEmpty,Boolean throwIfSequenceNotSingle, 投影投影,NavigationSource源,列表1 linkLookups)
1.GetEnumerator()at System.Collections.Generic.List
at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression) at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetEnumerator[TElement](Expression expression) at Microsoft.Xrm.Sdk.Linq.Query1..ctor(IEnumerable
1集合)
在System.Linq.Enumerable.ToList [TSource](IEnumerable`1 source)at aspirets.crm.test.Program.Main(String [] args)in C:\ Users \ a_marshall \ documents \ visual studio 2010 \ Projects \ aspirets.crm \ aspirets.crm.test \ Program.cs:第37行at System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)在System.AppDomain.ExecuteAssembly(String assemblyFile, 证据assemblySecurity,String [] args)at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 ignoreSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态)at System.Threading.ThreadHelper.ThreadStart()
答案 0 :(得分:5)
而不是Users.Id
,请尝试Users.SystemUserId
。同样,请尝试Teams.Id
。
Teams.TeamId
至于其工作原因,我不知道任何说明这一点的文档,但由于生成的早期绑定文件中的实体继承自Entity
,因此它们必然具有Id
属性。但是,因为早期绑定OrganizationServiceContext
将实体属性直接映射到CRM数据库,其表格不包含Id
列,使用Id
属性和LINQ提供程序获胜不行,所以你必须使用实际的数据库/模式名称。