views:

69

answers:

1

i need to evaluate generic type at runtime using Type.GetType()

Type t  = Type.GetType("className");
Table<t> table = dataContext.GetTable<t>();

any ideas please ??

+1  A: 

Well, normally you need to get the generic method (e.g. with Type.GetMethod), then call MethodInfo.MakeGenericMethod, then invoke it.

However, is there any reason you don't just want to call DataContext.GetTable(Type)?

You won't be able to use the table generically anyway... so is ITable (the return type of GetTable(type)) good enough for you?

Jon Skeet
thnx jon, so how can query ITable is that possible ??
mahmoud
@mahmoud: Yes - it extends `IQueryable`. But it won't be terribly *easy* to query it if you don't know the type. If you could explain more about what you're trying to do, that would help.
Jon Skeet
i have n number of identical Tables in DB (identical in structure) , will be mapped to n class in DataModeli want to create a generic solution to work with all of them is that possible ?thnx in advance
mahmoud
@mahmoud: I'm not sure, to be honest. It's *possible* that you could create an interface that all of them implement... but I don't know enough about LINQ to SQL to say for sure.
Jon Skeet
@jon : thanks very much for your reply
mahmoud