RE: Dynamic LINQ ITable



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


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<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
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<ClientTable> table = 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<ClientTable> table = 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?



.



Relevant Pages

  • RE: adp application hangs
    ... I understand that your clients using ADE file sometimes experience ... Since the issue occurs when typing text info in fields, ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.access.adp.sqlserver)
  • RE: Sharing Objects Between ASP.NET "Sites"/Projects
    ... Based on your description, you're building two websites, one for mobile ... clients and one for normal pc clients and they have same functionality and ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Report as Snapview picking up default printer settings
    ... I understand that some clients cannot print report properly. ... different database or sample northwind database. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.access.reports)
  • RE: BizTalk Explorer not showing
    ... If BizTalk Explorer on other clients can connect to the DB without problem, ... You may run something like DTCPing on both server and problem ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.biztalk.general)
  • RE: OWA spell check problem
    ... Does this problem only occur on Windows XP clients? ... 825430 Overview of the spelling checker in Outlook Web Access for Exchange ... Click Settings next to Anonymous Access & Authentication Settings ... Microsoft Online Partner Support ...
    (microsoft.public.exchange2000.general)