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<HMContext>(null);
}
/// ... ///
public virtual DbSet<Medicine> Medicines { get; set; }
public virtual DbSet<MedicineGeneric> MedicineGenerics { get; set; }
public virtual DbSet<MedicineStrength> MedicineStrengths { get; set; }
public virtual DbSet<MedicineType> MedicineTypes { get; set; }
public virtual DbSet<MedicineDosage> MedicineDosages { get; set; }
public virtual DbSet<MedicineCategory> MedicineCategories { get; set; }
public virtual DbSet<MetricPrefix> MetricPrefixes { get; set; }
public virtual DbSet<Unit> Units { get; set; }
///...///
}