title: Implementing OWIN using existing Database name validation?
body: <p>I wish to implement OWIN as per the example I could find here:
  <a href="http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api" rel="nofollow">http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api</a> </p>
  
  <p>However, since this way of working is new to me especially using my self created database I would like some guidance.
  I can submit my registration request without a problem.</p>
  
  <p>The post takes me to the AccountController:</p>
  
  <pre><code>    [AllowAnonymous]
      [Route("Register")]
      public async Task&lt;IHttpActionResult&gt; Register(RegisterBindingModel model)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          try { 
              var email = model.Email;
              var password = model.Password;
  
              var user = new users() {
                   Email = email,
                   PasswordHash = password,
                   Password = password
              };
  
              IdentityResult result = await UserManager.CreateAsync(user, model.Password);
  
              if (!result.Succeeded)
              {
                  return GetErrorResult(result);
              }
  
              return Ok();
          }
          catch(Exception ex)
          {
              throw;
          }
      }
  </code></pre>
  
  <p>This triggers the below code:</p>
  
  <pre><code>    public ApplicationUserManager UserManager
      {
          get
          {
              return _userManager ?? Request.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
          }
          private set
          {
              _userManager = value;
          }
      }
  </code></pre>
  
  <p>ApplicationUserManager:</p>
  
  <pre><code>public class ApplicationUserManager : UserManager&lt;users&gt;
  {
      public ApplicationUserManager(IUserStore&lt;users&gt; store)
          : base(store)
      {
      }
  
      public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context)
      {
          var manager = new ApplicationUserManager(new UserStore&lt;users&gt;(context.Get&lt;DaumAuctionEntities&gt;()));
          var dataProtectionProvider = options.DataProtectionProvider;
  
          // Configure validation logic for passwords
          manager.PasswordValidator = new PasswordValidator
          {
              RequiredLength = 6,
              RequireNonLetterOrDigit = false,
              RequireDigit = false,
              RequireLowercase = true,
              RequireUppercase = true,
          };
  
          if (dataProtectionProvider != null)
          {
              manager.UserTokenProvider = new DataProtectorTokenProvider&lt;users&gt;(dataProtectionProvider.Create("ASP.NET Identity"));
          }
  
          return manager;
      }
  }
  </code></pre>
  
  <p>But for some weird reason I'm getting</p>
  
  <pre><code> modelState: {undefined: ["Name cannot be null or empty."]}
  </code></pre>
  
  <p>Even though I don't use name anywhere?! Where is this name coming from?</p>
  
  <p>So I presume I'm doing something wrong but it's hard to debug without a clear explanation on how to implement OWIN with an existing DB.</p>
  
  <p>Below my context/entity and users table that I would like to use to store me user data.</p>
  
  <p>context:</p>
  
  <pre><code>public partial class DaumAuctionEntities : IdentityDbContext&lt;users&gt;
  {
      public DaumAuctionEntities()
          : base("name=DaumAuctionEntities")
      {
      }
  
      public DbSet&lt;addresses&gt; addresses { get; set; }
      public DbSet&lt;auctions&gt; auctions { get; set; }
      public DbSet&lt;images&gt; images { get; set; }
      public DbSet&lt;users&gt; users { get; set; }
  }
  </code></pre>
  
  <p>users : IdentityUser:</p>
  
  <pre><code>public partial class users : IdentityUser
  {
      public override string UserName
      {
          get
          {
              return Email;
          }
          set
          {
              Email = value;
          }
      }
  
      override public string PasswordHash
      {
          get
          {
              return Password;
          }
  
          set
          {
              Password = value;
          }
      }
  
      public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;users&gt; manager, string authenticationType)
      {
          // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
          var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
          // Add custom user claims here
          return userIdentity;
      }
  }
  
  public partial class users
  {
      public int Id { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public System.DateTime CreatedDate { get; set; }
      public Nullable&lt;System.DateTime&gt; ModifiedDate { get; set; }
  
  }
  </code></pre>
  
  <h1>Edit:</h1>
  
  <p>If I add UserName back to my new users object before I try to call CreateAsync, the error is gone but I get another one instead:</p>
  
  <pre><code>"The specified type member 'UserName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."
  </code></pre>
  
  <h1>Edit II:</h1>
  
  <p>I also have this issue in the tutorial code! This is just a freaking bug in .NET?</p>
  
  <h1>Edit III</h1>
  
  <p>I tried to do an override as you can see in the partial class Users above. But I still have the same error.</p>