In my project I have some tables that are not managed by Code First (the ASP.NET Users and Roles tables). I want to reference those tables from my own tables, just to make sure the data is integral. I am not adding any constraints to the ASP.NET tables, just to my own, so I’m fairly certain this won’t bother the ASP.NET membership code.
I have my own Users table which will hold additional user information:
class MyUser
{
public int UserId { get; set; }; // The primary key of the table
public Guid UserGuid { get; set; } // References aspnet_Users.UserGuid
...
}
I basically want Code First to execute the following SQL when creating the MyUsers table:
ALTER TABLE MyUsers ADD FOREIGN KEY (UserGuid) REFERENCES aspnet_Users(UserId)
and I want it to run it properly when performing migrations etc…
How can this be done?
So basically, I think you need to use the reverse engineer tool to generate the code first POCOs for the ASP.NET umembership tables. You can then reference these POCOs directly from your MyUser class for example.