Microsoft Dynamics 2011 N: N LINQ query with where clause containing Guid

I built a simple query to return a membership to Team Users (N: N ratio). This works fine for all users, however, when I add a where clause to restrict a specific user, it throws a crash exception (see the stacktrace table below).

Strange this works great with "where Users.FullName.StartsWith (" Alex "). Is the implementation of the Dynamics CRM SDQ LINQ Guide implemented in the sentences?

Any tips?

Code example

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

Stacktrace

: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime , ProxyRpc & rpc) System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime, Object [] ins, [], - TimeSpan) System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime, Object [] ins, [] ) System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage Call, ProxyOperationRuntime) System.ServiceModel.Channels.ServiceChannelProxy.Invoke( )

, [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage( reqMsg, IMessage retMsg) System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData & msgData, Int32) 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 <. > C_DisplayClass19.b_18 (IOrganizationService 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 & moreRecords) Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute [TElement] (QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean 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.GetEnumerator() System.Collections.Generic.List 1..ctor(IEnumerable 1 )
System.Linq.Enumerable.ToList [TSource] ( IEnumerable'1) aspirets.crm.test.Program.Main(String [] args) C:\Users\a_marshall\\ 2010\Projects\aspirets.crm\aspirets.crm.test\Program.cs: 37 System.AppDomain._nExecuteAssembly ( RuntimeAssembly, String [] args) System.AppDomain.ExecuteAssembly(String assemblyFile, . , String [] args) Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
System.Threading.ThreadHelper.ThreadStart_Context ( )
System.Threading.ExecutionContext.Run(ExecutionContext executeContext, ContextCallback, , ignoreSyncCtx) System.Threading.ExecutionContext.Run(ExecutionContext executeContext, ContextCallback, ) System.Threading.ThreadHelper.ThreadStart()

+3
1

Users.Id Users.SystemUserId. , Teams.Id, Teams.TeamId.

, , - , , Entity, Id. , OrganizationServiceContext CRM, Id, Id LINQ, , 'd /.

+5

All Articles