컨텍스트의 테이블을 반복 한 다음 해당 테이블의 속성을 사용하여 컨텍스트의 모든 열을 열심히로드합니다. 다른 질문을 통해 도움을 받았지만 실제 테이블의 열 속성을 반복하는 방법을 알 수없는 것 같습니다.컨텍스트에서 테이블 반복 및 해당 테이블의 속성
최종 작업 코드 :
public static void DisableLazyLoading(this DataContext context)
{
DataLoadOptions options = new DataLoadOptions();
var contextTables = context.GetType().GetProperties().Where(n => n.PropertyType.Name == "Table`1");
foreach (var contextTable in contextTables)
{
var tableType = contextTable.GetValue(context, null).GetType().GetGenericArguments()[0];
var tableProperties = tableType.GetProperties().Where(n => n.PropertyType.Name != "EntitySet`1");
foreach (var tableProperty in tableProperties)
{
ParameterExpression paramExp = Expression.Parameter(tableType, "s");
Expression expr = Expression.Property(paramExp, tableProperty.Name);
options.LoadWith(Expression.Lambda(expr, paramExp));
}
}
context.LoadOptions = options;
}
왜 그때의 속성을 얻을 수 있습니까? – GenericTypeTea
'PropertyInfo' 클래스 중. 나는 실제 테이블을 얻는 방법을 알아낼 수 없다. –