DB 컨텍스트의 OnModelCreating() 메서드를 빠르게 재정의하는 방법이 있습니다.
이 방법 :
public class AppContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// ...
modelBuilder.Entity<YourModelEntity>.Property(p => p.Birth).IsOptional();
}
}
또는 다른 적절한 방법은 당신이 당신의 모델에 대한 일반적인 EntityTypeConfiguration 유형의 확장 클래스를 만든 다음 OnModelCreating에서 DBModelBuilder() 메소드이이 특정 구성을 추가 할 수 있다는 것입니다 방법 :
public class YourModelTypeConfiguration : EntityTypeConfiguration<YourModelType>
{
public YourModelTypeConfiguration()
{
// ... some other configurations ;
Property(p => p.Birth).IsOptional();
}
}
참고가
using System.Data.Entity.ModelConfiguration;
필요 클래스 파일 상단에3210
.
그런 다음 OnModelCreating() 메소드에이를 추가해야합니다 :
public class AppContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// quick and dirty solution
// modelBuilder.Entity<YourModelEntity>.Property(p => p.Birth).IsOptional()
// cleaner solution
modelBuilder.Configurations.Add(new YourModelTypeConfiguration());
}
}
이 방법은 당신이 당신의 특정 구성이 분리 유지하고 모든 것을 함께 혼합하지 않습니다.
코드 첫 번째 마이그레이션을 적용 할 때 "출생"데이터베이스 필드는 null 가능해야합니다.
이 정보가 도움이되기를 바랍니다.
데이터를 편집하는 경우보기에서 데이터 모델을 사용하지 않아야합니다. 뷰 모델을 사용해야하며'DateTime'은'[Required]'로 꾸밀 수 있지만 데이터 모델에서는 생략 할 수 있습니다. –