views:

53

answers:

0
var defaultRole=ZAssociateRoles.Single(r=>r.RoleName=="Associate");
var allAssociates=(from a in ZAssociates
    join arm in Associate_role_maps
    on a.UserName equals arm.UserName into leftArm
    from la in leftArm.DefaultIfEmpty()
    join r in ZAssociateRoles
    on la.AssociateRoleId equals r.AssociateRoleId into leftOuterRole
    from lor in leftOuterRole.DefaultIfEmpty(defaultRole) //throws exception
    select new {a,lor.RoleName}).Dump();

the exception is NotSupportedException: Unsupported overload used for query operator 'DefaultIfEmpty'

if the linq is too complex here's what it would be in sql I believe:

select a.*,case when r is null then 'Associate' else r.RoleName end
 from associates a
 left join associate_role_map arm
 on a.UserName=arm.UserName
 left join ZAssociateRole r
 on arm.associateRoleId=r.associateRoleId

if I leave the defaultRole argument out it works, is there an easy way to provide a default value for the case when the many-to-many table doesn't have a record for an associate?