linq question

C

CSharper

I would like know, will it be possible to run a linq statement
generated on the fly by a program?

Lets say, I have string like the following
string t = "from c in doc.Decentents('Value') select c";

Is there anyway I would able to run this?

Thanks.
 
J

Jon Skeet [C# MVP]

CSharper said:
I would like know, will it be possible to run a linq statement
generated on the fly by a program?

Lets say, I have string like the following
string t = "from c in doc.Decentents('Value') select c";

Is there anyway I would able to run this?

You can use the CSharpCodeProvider to compile code, if that helps.
 
C

CSharper

M

Michael F. Sargent

If you look in the following path file:\\C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\ you will see a zip file called
CSharpSamples.zip. Inside is a folder called "LinqSamples" and another called "LanguageSamples". The LinqSamples includes a folder
called DynamicQuery which shows how to do this.

For example:

var query =
db.Customers.
Where("City = @0 and Orders.Count >= @1", "London", 10).
OrderBy("CompanyName").
Select("new(CompanyName as Name, Phone)");

I have used this will LINQ to SQL and it works well. I don't understand why Microsoft didn't make this a standard part of .NET 3.5
(since they almost did it with LinqDataSource).

I haven't tried it with XML. Let us know how it works.

Mike

You can use the CSharpCodeProvider to compile code, if that helps.

--
Jon Skeet - <[email protected]>
Web site:http://www.pobox.com/~skeet
Blog:http://www.msmvps.com/jon_skeet
C# in Depth:http://csharpindepth.com

Thanks Jon, What I am trying to do is similar to SQL, I want to build
the Linq on the fly on which columns to display and then like sql
executescalar or something, is it possible to run the build linq? I
want to execute the linq statement I build.
 
F

Frans Bouma [C# MVP]

Michael said:
If you look in the following path file:\\C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\ you will see a zip file called
CSharpSamples.zip. Inside is a folder called "LinqSamples" and another called "LanguageSamples". The LinqSamples includes a folder
called DynamicQuery which shows how to do this.

For example:

var query =
db.Customers.
Where("City = @0 and Orders.Count >= @1", "London", 10).
OrderBy("CompanyName").
Select("new(CompanyName as Name, Phone)");

I have used this will LINQ to SQL and it works well. I don't understand why Microsoft didn't make this a standard part of .NET 3.5
(since they almost did it with LinqDataSource).

why on earth would anyone use string based queries? You then can also
simply use SQL embedded in strings...

FB
I haven't tried it with XML. Let us know how it works.

Mike



Thanks Jon, What I am trying to do is similar to SQL, I want to build
the Linq on the fly on which columns to display and then like sql
executescalar or something, is it possible to run the build linq? I
want to execute the linq statement I build.


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top