i'm using linq. All my queries looks like var query = dc.GetTable<myType>()
.
I wish i could choose "myType" using a string parameter. I tried to create a Type object using reflection, but th开发者_如何学Ce compiler doesn't recognize Type objects as class definitions.
Any suggestions? Thanks
There's a GetTable(Type) extension method which does exactly what you are looking for:
var query = dc.GetTable(Type.GetType("namespace.type, assembly"));
Why do you want that ? Using the generic method like you do now, gives you compile time checking support, whereas a string parameter not.
You can create an query instance as a generic Table<> object, but it won't be recognized in compile time. see Using Type objects as Type Parameters for Generics in C#
精彩评论