jmgibbo
jmgibbo

Reputation: 97

Joining two uniqueidentifiers using Linq

I think I have gone through every example on stackoverflow and I'm missing something fundamental to my issue.

I am trying to join two fields that have type "uniqueidentifier".

Below is my code:

   var s = (from d in db.aspnet_Memberships 
            join u in db.Merchants on d.aspnet_User equals u.aspnet_UserID  
            where u.MerchantID == MerchantID 
            select d.IsApproved).SingleOrDefault<System.String>();

I am getting the following error on the join "The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'."

Thank you for any assistance.

Upvotes: 0

Views: 27

Answers (1)

SBurris
SBurris

Reputation: 7448

Looks like you are trying to join the wrong things. Isn't aspnet_User a table?

Try:

var s = (from d in db.aspnet_Memberships 
         join u in db.Merchants on d.UserId equals u.aspnet_UserID  
         where u.MerchantID == MerchantID 
         select d.IsApproved).SingleOrDefault<System.String>();

Or:

var s = (from d in db.aspnet_Memberships 
         join u in db.Merchants on d.aspnet_User.UserId equals u.aspnet_UserID  
         where u.MerchantID == MerchantID 
         select d.IsApproved).SingleOrDefault<System.String>();

Also, I don't think the .SingleOrDefault is going to work, the query is selecting a bool.

Upvotes: 2

Related Questions