Problem: We enable our clients to create custom fields they wish to collect.
We want to use Dynamic LINQ to query this table (Just one).
My initial post and suggestion(s) are here: http://shrinkster.com/tzp
So I have a class called "ClientTable". All tables have some common fields,
but I need to add more at runtime.
Now I have a class that looks like:
--------------------
[Table(Name="ClientTable")]
public class ClientTable{
[Column(DbType = "VarChar(400) NOT NULL")]
public string FirstName { get; set; }
}
--------------------
Now this works great in dynamic LINQ when I do something like:
--------------------
Table<ClientTabletable = db.GetTable(typeof(ClientTable));
table.Where("FirstName == @0", "Bill");
--------------------
But if a client has a column in that table called "Age" I can't do something
like:
--------------------
table.Where("Age @0", 30);
--------------------
I get an error saying that "Age" doesn't exist, even though it exists in the
database. If I add the one Age property it works fine (which is
understandable).
So now, how can I dynamically add properties to ClientTable class at
runtime?
Is there a way to do something like this:
--------------------
Table<ClientTabletable = db.GetTable(typeof(Facade.CreateDynamicType))) as
Table<ClientTable>;
--------------------
As I'm sure you know the problem is the typeof(Facade.CreateDynamicType)
because "CreateDynamicType" is a property and not a class.
I've tried some quick tests by making the CreateDynamicType a method that
returns a Type and other stupid ideas that just didn't work.
Can something like this be done, should I pursue a solution to my problem
this way or should I just stick to a normal method like the:
Table<ClientTabletable = db.GetTable(typeof(ClientTable));
and then try to dynamically destory and create a new "ClientTable" object at
runtime?
Can I delete a type then create a new one on the fly? Any suggestions?