Quantcast
Channel: CRM Development Forum
Viewing all articles
Browse latest Browse all 888

Listing teams which a user does not administer

$
0
0

I'm trying to run a simple LINQ query which should list all the teams of which a system user is a member but not an administrator. So I'm trying something like;

private static void QueryTeamsAndUsersByLINQ(Guid userid)
{
    // context for query
    MyContext ctx = new MyContext(service);
    // a query to list all teams
    var queryTeams = from tm in ctx.TeamMembershipSet
                     join u in ctx.SystemUserSet on tm.SystemUserId.Value equals u.SystemUserId.Value
                     join t in ctx.TeamSet on tm.TeamId.Value equals t.Id
                     where (tm.SystemUserId == userid) && (t.AdministratorId.Id != userid)
                     select new { t.Name, u.FullName, tm.SystemUserId.Value, t.AdministratorId };
    // Some loop through that data
    foreach (var team in queryTeams)
    {
        Console.WriteLine("{0} - {1} - {2} - {3}", team.Name, team.FullName, team.Value, team.AdministratorId.Id.ToString());
    }
}

which returns the error "'TeamMembership' entity doesn't contain attribute with Name = 'administratorid'." Well I know that, I haven't asked for the AdministratorId from team membership I've asked for it from the team. So why it is looking in team membership for that property? If I remove the where clause referring to the administratorId it quite happily reports the correct Administrator Id from the correct table so why does adding the clause cause crm to look in the wrong table? and perhaps more to the point how do I make this damn thing do what I want.

(I really don't understand LINQ or more to the point why it does what it does when it chooses to not do what I think I've asked it do do :-( )


Viewing all articles
Browse latest Browse all 888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>