Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing complex user type linked to existing table in the new ASP.NET Identity
    primarykey
    data
    text
    <p>I'm trying to implement new ASP.NET Identity in my old project. I have an existing table called tda_Contacts in the database. The following code works fine without table attribute and creates all new identity related tables plus TdaContacts table. But when put existing table name in the table attribute ([Table("tda_Contacts")]), then it does nothing and throws Invalid object name 'dbo.UserSecrets' exeption. Also if I put different name in that attribute it works fine and creates a correct table with exactly the same columns and types as existing tda_Contacts.</p> <p>What am I doing wrong? How to force it to use my existing table? </p> <pre><code>public class IdentityUser : User { public int ContactID { get; set; } [ForeignKey("ContactID ")] public virtual TdaContact TdaContact { get; set; } } public class CustomUserContext : IdentityStoreContext { public CustomUserContext(DbContext db) : base(db) { Users = new UserStore&lt;IdentityUser&gt;(db); } } public class MyDbContext : IdentityDbContext&lt;IdentityUser, UserClaim, UserSecret, UserLogin, Role, UserRole&gt; { public MyDbContext() : base("Name=MyConnectionString") { } public IDbSet&lt;TdaContact&gt; TdaContacts { get; set; } } [Table("tda_Contacts")] public class TdaContact { [Key] public int ContactID { get; set; } [Required] [MaxLength(50)] public string FirstName { get; set; } [Required] [MaxLength(50)] public string LastName { get; set; } [MaxLength(255)] public string Email { get; set; } } </code></pre> <p>P.S. Just discovered that with precreated IdentityUsers table with correct foreign key to tda_Contacts it works as expected.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload