0

I tried to get the current user Id through the User.Identity but in vain, i found This post that guided me to do the following : Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey; i went through the same mistake as in This Post! however the solution provided didn't work in my case. I have an accounts model as

 public class Account
{

    public int ID { get; set; }
    ......

}

i want to link the billing information created to the currently logged in user so i tried doing the following as suggested

 if (User.Identity.IsAuthenticated)
            {
                Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey;
                billinginfo.User = db.AccountSet
                                   .Where(x => x.ID == userGuid).FirstOrDefault();  
            }

and i have the obvious error :

Operator '==' cannot be applied to operands of type 'int' and 'System.Guid' i couldn't get an answer from This Post i tried to convert the Guid to int but that generated a wrong id since the conversion is utmost to 64 bits

So i want to get the currently logged in user and be able to access all his attributes

Any help is appreciated!

Community
  • 1
  • 1
Zayat
  • 39
  • 4
  • 1
    Why don't you change `int ID` to `GUID ID` type? – user854301 Aug 23 '12 at 05:03
  • i am trying that, but i had to manually create a new guid for each uses, moreover (Guid)Membership.GetUser().ProviderUserKey returns a new guid >>currently checking that also the EF code first convention is to have the ID int – Zayat Aug 23 '12 at 05:46

1 Answers1

1

You cannot compare integer with a GUID. It doesn't make sense. In order to relate the 2 tables you will have to use the same datatype column in both of them.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • finally found the solution >> was rather simple i linked them using the user name available in the Microsoft membership as follows ` if (User.Identity.IsAuthenticated) { String currentUser = Membership.GetUser().UserName; billinginfo.User = db.AccountSet .Where(x => x.UserName .Equals( currentUser )).FirstOrDefault(); }` Thanks for help and comments :) – Zayat Aug 23 '12 at 06:08