I am new to asp.net mvc and entity framework so I could really use some help.
I want to have new class implemented into IdentityUser class with relationship one to one. For now I have this:
public class ApplicationUser : IdentityUser
{
public virtual MapPosition MapPosition { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<MapPosition> MapPositions { get; set; }
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
public class MapPosition
{
[Key, ForeignKey("ApplicationUser")]
public string UserId { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public int PositionX { get; set; }
public int PositionY { get; set; }
}
Everything is great, new table has been created but how can I make it so everytime new user is created application also creates MapPosition entry with default values of 0 for both properties?