tags:

views:

29

answers:

1

I have two Tables:

Table 1: Client

Fields: Id_Client Char 5 Name_Client Char 50

Table 2: Country

Fields: Id_Country Char 4 Name_Country Char 80 Population Int 15

With Sql I can make this 2 queries

Select Id_Client, Name_Client from Client

Select Id_Country, Name_Country, Population from Country

I wan to do this 2 queries in only one using Linq SQL. I think something like this

string Option = "";

string SelectFields = ""; string TableName = "";

if (Option == "Client"){

   SelectFields = "Id_Client, Name_Client";
   TableName = "Client";

} else{

   SelectFields = "Id_Country, Name_Country, Population";
   TableName = "Country";

}

Select "SelectFields" from "TableName"

I'm a Visual Fox Pro Developer and using Evaluate (macros) this is very easy to do. Is possible to do something like this on Linq To Sql???

Sorry for my poor english

A: 

You will want to look into dynamic linq to sql, this will allow you to pass in the expression as a string.

In the end you will end up with something like the following:

IQueryable<SomeItem> = results = context.SomeItem.Where("SomeItemID > 30 AND SomeItemID < 40");

Additional Information, Using Dynamic Linq

Mark
I saw that, but is very poor, i cant do something really dynamic. You cant use 1 "query" with 2 or more tables.Any other idea??. PleaseThanks.Sorry for my poor English
Mark Comix