Codefirst "invalid column name xxx" ?
BaseEntity
public abstract class BaseEntity
{
public int Id { get; set; }
}
User
public class User : BaseEntity
{
public User()
{
Roles = new HashSet<Role>();
}
public string UserName { get; set; }
public string DisplayName { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string ProfileImageUrl { get; set; }
public DateTime? LastLoginDate { get; set; }
public string LastLoginIp { get; set; }
public int? LanguageId { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
user mapping
public class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
ToTable("User");
HasKey(x => x.Id);
Property(x => x.DisplayName).HasMaxLength(100);
Property(x => x.Email).HasMaxLength(250);
Property(x => x.LastLoginIp).HasMaxLength(20);
Property(x => x.Password).HasMaxLength(50);
Property(x => x.ProfileImageUrl).HasMaxLength(500);
Property(x => x.UserName).HasMaxLength(50);
HasMany(h => h.Roles).
WithMany(e => e.Users).
Map(
m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("RoleId");
m.ToTable("User_Role");
}
);
}
}
test metod
private MvcProjectContext _context;
private IUnitOfWork _uow;
private IUserService _userService;
[TestInitialize]
public void TestInitialize()
{
_context = new MvcProjectContext();
_uow = new UnitOfWork(_context);
_userService = new UserService(_uow);
}
[TestMethod]
public void TestMethodAddUser()
{
_userService.Insert(new User
{
DisplayName = "test display name",
Email = "test_email@mail.com",
LanguageId = 1,
LastLoginDate = DateTime.Now,
LastLoginIp = "192.168.1.1",
Password = "12345",
ProfileImageUrl = "profile image",
UserName = "test_user"
});
Assert.AreEqual(1,_uow.SaveChanges());
}
I debugged it and checked it, user is adding dbcontext, but when
savechanges method firing, I get error
"invalid column name 'LanguageId'"
I cant find any solution. In DB there is column that named 'LanguageId'.
it does not seem to be something missing. Any advice?
No comments:
Post a Comment