title: aspnet identity using guid as key
body: <p>I am trying to use Guid's instead of strings for my primary key and have followed the following posts: <a href="https://stackoverflow.com/questions/19553424/how-to-change-type-of-id-in-microsoft-aspnet-identity-entityframework-identityus">How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser</a> and 
  <a href="https://stackoverflow.com/questions/19553424/how-to-change-type-of-id-in-microsoft-aspnet-identity-entityframework-identityus/19577113#19577113">How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser</a></p>
  
  <p>I updated to the latest prerelease packages of aspnet identity</p>
  
  <blockquote>
    <p>Microsoft ASP.NET Identity Core 2.0.0-beta1</p>
    
    <p>Microsoft ASP.NET Identity EntityFramework 2.0.0-beta1</p>
  </blockquote>
  
  <p>and edited my User to allow for Guid's instead of the default string, I then created my own dbContext and usermanager, however every time I try to login I get the following error: </p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException: Operand type clash:
    uniqueidentifier is incompatible with int</p>
  </blockquote>
  
  <p>for this line: </p>
  
  <blockquote>
    <p>var user = await UserManager.FindAsync(model.UserName,
    model.Password);</p>
  </blockquote>
  
  <p>I have checked to make sure that all the fields in the database are definitely uniqueidentifiers and I'm not sure what to try next, below is the code I am currently using:</p>
  
  <p>User objects:</p>
  
  <pre><code>public class GuidRole : IdentityRole&lt;Guid, GuidUserRole&gt;
      {
          public GuidRole()
          {
              Id = Guid.NewGuid();
          }
          public GuidRole(string name) : this() { Name = name; }
      }
      public class GuidUserRole : IdentityUserRole&lt;Guid&gt; { }
      public class GuidUserClaim : IdentityUserClaim&lt;Guid&gt; { }
      public class GuidUserLogin : IdentityUserLogin&lt;Guid&gt; { }
  
      public class User : IdentityUser&lt;Guid, GuidUserLogin, GuidUserRole, GuidUserClaim&gt;
      {
          public User()
          {
              Id = Guid.NewGuid();
          }
  
          public User(string name) : this() { UserName = name; }
  
          public string FirstName { get; set; }
          public string LastName { get; set; }
      }
  </code></pre>
  
  <p>dbContext: </p>
  
  <pre><code>public class newDbContext : IdentityDbContext&lt;User, GuidRole, Guid, GuidUserLogin, GuidUserRole, GuidUserClaim&gt;
  {
      public newDbContext()
          : base(nameOrConnectionString: "defaultConnection") { }
  
      public newDbContext(string connectionString)
          : base(nameOrConnectionString: connectionString) { }
  
      static newDbContext()
      {
          Database.SetInitializer&lt;newDbContext&gt;(null);
      }
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          // Use singular table names
          base.OnModelCreating(modelBuilder);
  
  
          modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
  
          modelBuilder.Entity&lt;User&gt;().ToTable("User").Property(p =&gt; p.Id).HasColumnName("UserID");
          modelBuilder.Entity&lt;User&gt;().Property(p =&gt; p.Email).HasColumnName("EmailAddress");
  
          modelBuilder.Entity&lt;GuidUserRole&gt;().HasKey(r =&gt; new { r.RoleId, r.UserId });
          modelBuilder.Entity&lt;GuidUserRole&gt;().ToTable("UserRole");
          modelBuilder.Entity&lt;GuidUserRole&gt;().Property(r =&gt; r.UserId).HasColumnName("UserID");
          modelBuilder.Entity&lt;GuidUserRole&gt;().Property(r =&gt; r.RoleId).HasColumnName("RoleID");
  
          modelBuilder.Entity&lt;GuidUserLogin&gt;().ToTable("UserLogin");
          modelBuilder.Entity&lt;GuidUserLogin&gt;().Property(r =&gt; r.UserId).HasColumnName("UserID");
  
          modelBuilder.Entity&lt;GuidUserClaim&gt;().ToTable("UserClaim");
          modelBuilder.Entity&lt;GuidUserClaim&gt;().Property(r =&gt; r.Id).HasColumnName("UserClaimID");
  
          modelBuilder.Entity&lt;GuidRole&gt;().HasKey&lt;Guid&gt;(r =&gt; r.Id);
          modelBuilder.Entity&lt;GuidRole&gt;().ToTable("Role");
          modelBuilder.Entity&lt;GuidRole&gt;().Property(r =&gt; r.Id).HasColumnName("RoleID");
  
          Configuration.ProxyCreationEnabled = false;
          Configuration.LazyLoadingEnabled = false;
      }
  
  }
  </code></pre>
  
  <p>and finally the user manager:</p>
  
  <pre><code>public class ApplicationUserManager : UserManager&lt;User, Guid&gt;
  {
      public ApplicationUserManager(string connectionString)
          : base(new UserStore&lt;User, GuidRole, Guid, GuidUserLogin, GuidUserRole, GuidUserClaim&gt;(new newDbContext()))
      {
  
          UserValidator = new UserValidator&lt;User, Guid&gt;(this) { AllowOnlyAlphanumericUserNames = false };
      }
  }
  </code></pre>