I get a slightly wierd exception when i try to add an object to my database. My code in my controller looks like this:
var user = db.UserActivation.Create();
user.UserId = Id
user.ActivationCode = activationCode;
db.UserActivation.Add(user);
db.SaveChanges();
Furthermore i have a model that looks like this:
public class UserActivation
{
[Key]
public int Id { get; set; }
public int UserId { get; set; }
public string ActivationCode { get; set; }
}
and a MySqlContext that looks like this:
public class MySqlContext : DbContext
{
public MySqlContext() : base("MySql")
{
//this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Users> Users { get; set; }
public DbSet<UserActivation> UserActivation { get; set; }
}
In my error i can see in the inner exception, that it selects the wrong database, it says:
[MySql.Data.MySqlClient.MySqlException {"Table 'bkrt_dk_db.UserActivations' doesn't exist"}
This makes absolutely no sense, since i both in my model, context and controller specifically have called it UserActivation
and NOT UserActivations
This is my stacktrace:
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
at System.Data.Entity.DbContext.SaveChanges()
at Learning.Controllers.AuthController.emailConirmation(String email, String name) in c:\Users\Projects\Learning\Learning\Controllers\AuthController.cs:line 146
at Learning.Controllers.AuthController.<>c__DisplayClass4.<Registration>b__2() in c:\Users\Projects\Learning\Learning\Controllers\AuthController.cs:line 107
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
I can see that others have stated that it has something to do with pluralization, and EF making the db architecture behind the scenes.. but really i dont know about pluralization and why i get this error.