Code First Default Value – Easy way

There is a easy way to set default values in Entity Framework   Code first. all you need to do is just set your default value in your constructor. after all entity is also behave like an object. below example show how to set default value of IsActive Property

 public class MaterialCategory

   public MaterialCategory()
   public int Id { get; set; }
   public string Name {get;set; }
   public string Description { get; set; }
   public bool IsActive { get;set;}


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.