I\'m using VS2013
When I try to create an \"MVC 5 Controller with views using entity Framework\" I get the following error:
the
Please check all the Models are registered in context
Example:
You have a Model like this
public class MedicineStrength
{
[Key]
public int Id { get; set; }
public int? MedicineId { get; set; }
[ForeignKey("MedicineId")]
public Medicine Medicine { get; set; }
public double Strength { get; set; }
public int? MetricPrefixId { get; set; }
[ForeignKey("MetricPrefixId")]
public virtual MetricPrefix MetricPrefix { get; set; }
public int? UnitId { get; set; }
[ForeignKey("UnitId")]
public virtual Unit Unit { get; set; }
public int? MedicineTypeId { get; set; }
[ForeignKey("MedicineTypeId")]
public virtual MedicineType MedicineType { get; set; }
}
Check all virtual
Model instances are registered in in context like this
public class HMContext : DbContext
{
public HMContext()
: base("name=HMContext")
{
Database.SetInitializer(null);
}
/// ... ///
public virtual DbSet Medicines { get; set; }
public virtual DbSet MedicineGenerics { get; set; }
public virtual DbSet MedicineStrengths { get; set; }
public virtual DbSet MedicineTypes { get; set; }
public virtual DbSet MedicineDosages { get; set; }
public virtual DbSet MedicineCategories { get; set; }
public virtual DbSet MetricPrefixes { get; set; }
public virtual DbSet Units { get; set; }
///...///
}