RE: Dynamic LINQ ITable
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Mon, 21 Jan 2008 03:24:56 GMT
Hi EDBrian,
Based on your issue description, I think the main problem here is that if
you want to use a certain column property in expression, that property need
to be statically exists in the table class(you can not dynamically add it
at runtime, at least can not do it at LINQ level).
Therefore, IMO, what you need here is dynamically define and build a
certain table class(assembly) and referece the class in it. In .net, the
way to create type/assembly dynamically is using Reflection and CodeDom
feature:
#Reflection and Dynamic Classes
http://www.osix.net/modules/article/?id=126
#Dynamic building and execution of assembly using CodeDome & Reflection
http://www.c-sharpcorner.com/UploadFile/pradeep.tiwari/DynamicBuildingandExe
cutionOfAssemblyUsingCodeDomeAndReflection08212006072200AM/DynamicBuildingan
dExecutionOfAssemblyUsingCodeDomeAndReflection.aspx
Also, here I found a web article mentioned something combine CodeDom and
Linq:
#CodeDom extensions and dynamic LINQ (string/script to LINQ emitting)
http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-lin
q-stringscript-to-linq-emitting/
Hope this helps some.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "EDBrian" <preport@xxxxxxxxxxxxxxxxx>
From: "EDBrian" <preport@xxxxxxxxxxxxxxxxx>
Subject: Dynamic LINQ ITable
Date: Fri, 18 Jan 2008 13:55:30 -0800
collect.
Problem: We enable our clients to create custom fields they wish to
We want to use Dynamic LINQ to query this table (Just one).fields,
My initial post and suggestion(s) are here: http://shrinkster.com/tzp
So I have a class called "ClientTable". All tables have some common
but I need to add more at runtime.something
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<ClientTable> table = 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
like:the
--------------------
table.Where("Age > @0", 30);
--------------------
I get an error saying that "Age" doesn't exist, even though it exists in
database. If I add the one Age property it works fine (which isas
understandable).
So now, how can I dynamically add properties to ClientTable class at
runtime?
Is there a way to do something like this:
--------------------
Table<ClientTable> table = db.GetTable(typeof(Facade.CreateDynamicType)))
Table<ClientTable>;at
--------------------
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<ClientTable> table = db.GetTable(typeof(ClientTable));
and then try to dynamically destory and create a new "ClientTable" object
runtime?
Can I delete a type then create a new one on the fly? Any suggestions?
.
- References:
- Dynamic LINQ ITable
- From: EDBrian
- Dynamic LINQ ITable
- Prev by Date: Re: Regex Q (Another one)
- Next by Date: Re: Regex Q (Another one)
- Previous by thread: Re: Dynamic LINQ ITable
- Next by thread: datagridview saving
- Index(es):
Relevant Pages
|
|