Have some code:
using (var ctx = new testDataContext())
{
var options = new DataLoadOptions();
options.LoadWith<TableA>(p => p.TableB);
...
var tmp = ctx.TableA.Where(p => p.TableB != null);
...
}
Want to wrap it like:
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);
Or something like that.
The idea is – to use same method, for diffrent tables, which are passed as parameter, to some function.
I know about linq2sql inheritance, but i want to know, is it possible to do another way?
If the particular property/properties you’re going to inspect are fixed in number and known at compile time, then adding a particular interface for those tables (via partial class, I’d assume) would likely be easiest and still type-safe. Otherwise, you’re looking at reflection, or using dynamic, or perhaps using Dynamic LINQ depending on the goals.
Giving a more concrete example might help since it’s not clear to me whether it’s something you want to take specific tables that fit a pattern for, or any table no matter what.