tags:

views:

66

answers:

1

Hi, I have a table Admins, which creates a relationship between Users and Locations:

ID - numeric (PK)
UserId - uniqueidentifier (FK to UserId in aspnet_Users table)
LocationId - numeric

Now I want to execute command:

IQueryable<decimal> location_ids = (from m in _db.Admins
                                    where m.UserId.Equals( new Guid("c5d3dc0e-81e6-4d6b-a9c3-faa802e10b7d")) && m.LocationId.Equals(conf.umisteni.Budova.ID)
                                    select m.LocationId);

But for some reason (I guess the UsersId is FK) m.UserId can't be resolved. So I tried to use

m.aspnet_UsersReference.Value.UserId

But then the decision statement

if (!location_ids.Any())

fails with exception

System.NotSupportedException: The specified type member 'aspnet_UsersReference' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

What should I do in order to get the enumerable list of LocationIds?

Thanks in advance.

+2  A: 

You're missing a 'Users' and a dot:

var location_ids = (from m in _db.Admins
                    where m.Users.UserId.Equals( 
                        new Guid("c5d3dc0e-81e6-4d6b-a9c3-faa802e10b7d")) &&   
                        m.LocationId.Equals(conf.umisteni.Budova.ID)
                    select m.LocationId);

Essentially, you need to use the relationship "Users" directly.

Craig Stuntz
Obviously I have forgotten to explain table aspnet_Users. The main attribute of it is UserId - PK and uniqueidentifier. So no, the dot is not there.
Trimack
OK, connect the dots, then. You have a relationship on the Users property. The gist of my answer is that you're not using it. I guessed the name of the key and the relationship wrong, but the answer is still the right direction: *Use the relationship instead of bypassing it.* Then your query will work in LINQ to Entities. I'll update my answer with another guess at the right names, though.
Craig Stuntz