0

I need to mirate my dbContext class , but I got this error :

System.Data.Entity.Edm.EdmEntityType: : EntityType 'UserType' has no key defined. Define the key for this EntityType. System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'UserTypes' is based on type 'UserType' that has no keys defined. 

here is my DbContext :

namespace seraydar.Models { public class Context : DbContext { public DbSet<UserType> UserTypes { get; set; } } } 

and here is my class:

public class UserType { [Key] int id { get; set; } [Required, MaxLength(30, ErrorMessage = "Name can not be longer than 30 characters."), Display(Name = "User Type")] string userType { get; set; } } 

I just got confused!

1 Answer 1

1

By default, Entity Framework only looks at public properties. Your properties aren't public, so they are ignored. The easiest way to fix this is to make them public:

public class UserType { [Key] public int id { get; set; } [Required, MaxLength(30, ErrorMessage = "Name can not be longer than 30 characters."), Display(Name = "User Type")] public string userType { get; set; } } 

Migrations will then work properly.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.