My Clinic Class: public class Clinic { [Key] public int ClinicId { get; set; } [Display(Name="Clinic Name")] public string ClinicName { get; set; } [Display(Name = "Clinic Location")] public string ClinicLocation { get; set; } } My DataContext: public class DataContext: DbContext { public DataContext() : base("Padcc") { } public DbSet<Clinic> Clinics { get; set; } public new IDbSet<TEntity> Set<TEntity>() where TEntity : class { return base.Set<TEntity>(); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); //modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>(); } } I have the method in my repository: public void InsertClinic(Clinic c) { clinic.Clinics.Add(c); } However when I redirect to the Create Clinic View and fill in the view, it give me an error: System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code Additional information: One or more validation errors were detected during model generation: DataAccess.Clinic: : EntityType 'Clinic' has no key defined. Define the key for this EntityType.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)