유창함 API를 사용하여, 당신은 다른 방법으로 당신의 맥락에서 각 유형의 반사를 사용할 수 있다면 당신은 code first custom conventions 를 사용할 수 있습니다. 각 POCO 및 루프마다 각 PROPERTY에 대해 char1을 소문자로 변경하는 이름을 설정하십시오.
modelBuilder.Entity<EFTestPoco>().Property(p=>p.UoM1).HasColumnName("camelCase");
편집 : 반성 도전은 ... 동적 람다를 포함 내가 루프가 .... 동적 람다 필요 이 :-)에게 너무 넓
을 내 입을 열어 실현 didnt는 요청까지 ... 이것은 내가 사용하는 코드 조각으로부터 잘라내어 붙여 넣기입니다. ... 난 당신이 식 합병증 라이브러리 System.Linq.Expressions 를 사용하거나 당신은 dymanic Linq에 문을 구축 할 Dynamic Lambda library 를 사용하여 쉽게 사용할 수있는 쉬운 /System.Linq.Dynamic 접근
를 사용합니다.
는 SO 여기 샘플 코드
// inside your context on model creating
//....
// repeat for each poco. // or reflect on thr context if feeling lazy and intellectual
var entity = new EntityTypeConfiguration<Poco>;
// Get the properties of a poco
foreach (var propInfo in typeof(T).GetProperties()) {
SetCamelCase<T>(propInfo,entity);
}
modelBuilder.Configurations.Add(entity);
....
} // end of ON model creating
private static void SetCamelCase<TModelPoco>(PropertyInfo propertyInfo,
EntityTypeConfiguration<TModelPoco> entity) where TModelPoco : BaseObject {
var camel = propertyInfo.Name.Substring(0, 1).ToLower() + propertyInfo.Name.Substring(1);
switch (propertyInfo.UnderLyingType().Name) {
case SystemDataTypeConstants.String :
var propLambdaString = System.Linq.Dynamic.DynamicExpression.ParseLambda<TModelPoco, string >(propertyInfo.Name);
entity.Property(propLambdaString).HasColumnName(camel);
break;
case SystemDataTypeConstants.Int32:
var propLambdaInt =System.Linq.Dynamic.DynamicExpression.ParseLambda<TModelPoco, int >(propertyInfo.Name);
entity.Property(propLambdaInt).HasColumnName(camel);
break;
// SystemDataTypeConstants. // and teh rest you may use...
}
}
public static Type UnderLyingType(this PropertyInfo propertyInfo) {
return Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
}
낙타 경우 귀하의 POCO 회원입니까? –