You should create a configuration class based on your model.In this you can specify the behavior of that property
public class SalesOrderConfiguration:EntityTypeConfiguration<salesorder>
{
public SalesOrderConfiguration()
{
Property(co => co.CustomerName).HasMaxLength(30).IsRequired();
Property(co => co.PONumber).HasMaxLength(10).IsOptional();
}
}
Your model class will look like below
public class SalesOrder
{
public int SalesOrderId { get; set; }
public string CustomerName { get; set; }
public string PONumber { get; set; }
}
You can specify the configuration class in your DbContext
public class SalesContext:DbContext
{
public SalesContext()
: base("DefaultConnection")
{
}
public DbSet<salesorder> SalesOrders { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new SalesOrderConfiguration());
}
}</salesorder>
Hope this helps