Click here to Skip to main content
15,888,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
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.


Please help
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900