【发布时间】:2012-02-05 13:48:22
【问题描述】:
有一些代码:
using (var ctx = new testDataContext())
{
var options = new DataLoadOptions();
options.LoadWith<TableA>(p => p.TableB);
...
var tmp = ctx.TableA.Where(p => p.TableB != null);
...
}
想把它包装成这样:
Action<T> test = x => {
using (var ctx = new testDataContext())
{
var options = new DataLoadOptions();
options.LoadWith<TableA>(p => typeof(x));
...
var tmp = ctx.TableA.Where(p => p.GetType().GetProperty(x) != null);
...
}
}
test(TableB);
test(TableC);
或者类似的东西。
这个想法是 - 对不同的表使用相同的方法,作为参数传递给某个函数。
我知道 linq2sql 继承,但我想知道,是否有可能做另一种方式?
【问题讨论】: