Linq join entity on to inherited entity

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 30-Apr-2010 02:50:18   

I have a "User" entity, I also have another entity called "ClientUser" which inherits from User.

I am trying to write a query that gets me all users that dont have an inheriting ClientUser. However joining ClientUser onto User appears to freak out the fragile linq provider.

I'm running this:

var list = from c in meta.User join cu in meta.ClientUser on c.UserId equals cu.UserId into tempCU from contacts in tempCU.DefaultIfEmpty() select c;

        if (canLogin != null)
            list = list.Where(p => p.CanLogon == canLogin.Value);

(canLogin did not equal null)

I get:

The multi-part identifier "LPLA_1.UserId" could not be bound.<br>The multi-part identifier "LPLA_1.ClientId" could not be bound.<br>The multi-part identifier "LPLA_1.SecondaryEmail" could not be bound.<br>The multi-part identifier "LPLA_1.Title" could not be bound.<br>The multi-part identifier "LPLA_1.Notes" could not be bound.<br>The multi-part identifier "LPLA_1.IsMainContact" could not be bound.

The fields it's mentioning there are from ClientUser.

So I would add another line like: where contacts == null to filter out those users... but I'm not getting that far.

(ClientUser is properly configured as a subclass of User in the llbl designer)

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 30-Apr-2010 02:54:16   

Got somethign going with this:


var cuIds = meta.ClientUser.Select(p => p.UserId);
            var list = from c in meta.User
                       where !cuIds.Contains(c.UserId)
                       select c;

Any better way?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Apr-2010 07:56:53   

I haven't tested this but I think it should work (read more about this:

var list = from c in meta.User
     where (c as ClientUserEntity) == null
     select c;
David Elizondo | LLBLGen Support Team