Code First using Visual Studio 2013 Template with Asp.Net Identity not working?
-
21-12-2019 - |
Question
Im working in this tutorial to update my AspNetUsers table with Code First.
This my IdentityModelClass:
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Data.Entity;
namespace MTGWeb.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public String Pais;
public String Email;
public DateTime UltimoLogin;
public DateTime FechaRegistro;
public String Tipo;
public Boolean Activado;
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
}
I already make this steps:
- Enable-Mirations - OK
- Add-Migration "BlaBla.."
- Update-Database
This steps executes correctly (not stop on error) but not changes anything. I followed all the tutorial steps, with my custom data, and debuggin the data send ok across the viewmodels, but the database is the problem.
I see the Table AspNetUsers and not any fields are saved. Any ideas? I can register users but only save the default data (Id, Username, PasswordHash,SecurityStamp and Discriminator
)
Solution
Entity framework maps properties to columns. Right now they are fields. Change them to auto properties like this...
public class ApplicationUser : IdentityUser
{
public String Pais { get; set; }
public String Email { get; set; }
public DateTime UltimoLogin { get; set; }
public DateTime FechaRegistro { get; set; }
public String Tipo { get; set; }
public Boolean Activado { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow