0
처음에는 Expression 및 Func과 함께 초보자입니다.일반 엔티티 프레임 워크 매핑
내 EF 매핑 클래스에서 코드 중복을 피하려고하는데 잘못된 데이터베이스가 붙어 있습니다.
public class EntityMap : EntityTypeConfiguration<Entity>
{
public EntityMap()
{
Property(x => x.PropertyA.Property);
Property(x => x.PropertyB.Property);
}
}
PropertyA
및 PropertyB
가 동일한 유형, 많은 재산 으로는, 간단한 방법으로이 리팩토링 매개 변수에 x => x.PropertyA
또는 PropertyB
을 통과 할 수 있나요 :
다음 예제 맵 클래스를 가지고 Property(x => x. methodParemeter Property);
과 같은 무엇입니까? 그리고 어떻게 ? 메소드는 다음과 같을 수 있습니다.
private void SubMap(Expression<Func<Entity, SubEntity>> propertyExpression, string prefix)
{
Property(x => x.propertyExpression.Property)
.HasColumnName(string.Format("{0}{1}", prefix,"columnName"));
}
어떻게 개선 될 수 있습니까? – DavidG
질문을 이해하지 못한다. 클래스 A 속성을 클래스 B에 자동으로 매핑 하시겠습니까? –
대신 .Property는 예를 들어'.MaxLength (50)'을 의미하며, 여러 속성에 대해 더 밀도가 높은 구문으로 호출하려고합니다 ? 그래서 당신은'{f => f.PropertyA, f => f.PropertyB} .ForEach (p => p.MaxLength (50))'와 같은 것을 원합니까? – CodeCaster