的Microsoft Dynamics 2011 N:N LINQ查询与其中含有的Guid条款(Mi

2019-09-16 15:54发布

我构建了一个简单的查询返回一个用户组的成员(N:N的关系)。 这为所有用户工作正常,但是当我添加一个where子句来限制它抛出一个错误异常的特定用户(见下面的堆栈跟踪)。

奇怪的是这个工作正常“其中Users.FullName.StartsWith(”亚历克斯“)”。 请问动态CRM SDK LINQ实现不支持在where子句中的GUID?

有什么建议?

示例代码

 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();
            }
        }

堆栈跟踪

服务器堆栈跟踪:在System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc&RPC)在System.ServiceModel.Channels.ServiceChannel.Call(字符串动作,布尔单向,ProxyOperationRuntime操作,对象[]项,对象[]奏,时间跨度超时)在System.ServiceModel.Channels.ServiceChannel.Call(字符串动作,布尔单向,ProxyOperationRuntime操作,对象[]项,在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage包括methodCall,ProxyOperationRuntime操作对象[]奏) )在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天消息)

在异常重新抛出[0]:在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天reqMsg,即时聊天retMsg)处Microsoft.Xrm System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&MSGDATA,的Int32类型)。 Sdk.IOrganizationService.Execute在Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest请求)在Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest请求)在Microsoft.Xrm.Client.Services(OrganizationRequest请求)。 OrganizationService。<> C_ DisplayClass19.b _18(IOrganizationService S)在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 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,布尔逻辑moreRecords)在Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute [TElement](QueryExpression QE,布尔throwIfSequenceIsEmpty,布尔throwIfSequenceNotSingle,投影投影,NavigationSource源,列表1 linkLookups)
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.Query
1 linkLookups)
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.Query
1 linkLookups)
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.Query
1。的GetEnumerator()在System.Collections.Generic.List 1..ctor(IEnumerable 1集)
在System.Linq.Enumerable.ToList [TSource](IEnumerable`1源)在aspirets.crm.test.Program.Main(字串[] args)在C:\用户\ a_marshall \文件\视觉工作室2010 \项目\ aspirets .crm \ aspirets.crm.test \ Program.cs的:线37在System.AppDomain._nExecuteAssembly(RuntimeAssembly组件,字串[] args)在System.AppDomain.ExecuteAssembly(字符串assemblyFile,证据assemblySecurity,字串[] args)在微软.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象的状态,布尔ignoreSyncCtx)在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态)在System.Threading.ThreadHelper.ThreadStart()

Answer 1:

取而代之的Users.Id ,尝试Users.SystemUserId 。 类似的,而不是Teams.Id ,尝试Teams.TeamId

至于为什么这个作品的原因,我不知道这个规定的任何文件,但由于在生成的早期绑定文件实体继承Entity ,它们一定有一个Id属性。 然而,由于早期绑定OrganizationServiceContext地图实体属性直接到CRM数据库,表,其中不包含Id列,使用Id属性与LINQ提供程序将无法正常工作,所以你必须使用实际的数据库/模式名称。



文章来源: Microsoft Dynamics 2011 N:N LINQ query with where clause containing Guid