I am getting this strange error from Entity framework , I cant figure out what I am doing wrong ..
My DB context code.
public DbSet<Interaction> Interactions { get; set; }
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
InteractionsDBContextConfig(modelBuilder);
base.OnModelCreating(modelBuilder);
}
public static void InteractionsDBContextConfig(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
// Interaction entity configuration.
modelBuilder.Entity<Interaction>()
.HasKey<int>(key => key.InteractionId);
modelBuilder.Entity<Interaction>()
.HasRequired<Form>(x => x.Form)
.WithMany()
.HasForeignKey(y => y.FormId);
modelBuilder.Entity<Interaction>()
.HasRequired<User>(x => x.User)
.WithMany()
.HasForeignKey(y => y.InteractionUserId);
// User entity configuration.
modelBuilder.Entity<User>()
.HasKey<int>(x => x.UserId);
modelBuilder.Entity<User>()
.Property(x => x.UserName)
.IsRequired()
.HasColumnAnnotation(
IndexAnnotation.AnnotationName,
new IndexAnnotation(
new System.ComponentModel.DataAnnotations.Schema.IndexAttribute() { IsUnique = true }
)
);
}
My Entity
public class Interaction
{
public int InteractionId { get; set; }
public int FormId { get; set; }
public string InteractionName { get; set; }
public virtual Form Form { get; set; }
public int InteractionUserId { get; set; }
public virtual User User { get; set; }
public DateTime Deadline { get; set; }
public int InteractionType { get; set; }
}
when I do the following
var db = dbcontext.Interactions.ToList();
I get the following error
{"Invalid column name 'InteractionType'."}
I cant figure out why the error is showing up , why cant Entity framework see my column ? Changing the name of the column doesnt seem to help.