Ich iteriere die Tabellen eines Kontexts und dann die Eigenschaften dieser Tabellen, um alle Spalten in einem Kontext eifrig zu laden. Ich erhielt einige Hilfe über eine andere Frage, aber ich scheine nicht in der Lage zu sein, herauszufinden, wie die Spalte Eigenschaften der eigentlichen Tabelle zu iterieren.
Endgültiger Arbeitscode:
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;
}