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";
}
开发者_JAVA技巧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
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
精彩评论