Creating select column list dynamically in DLinq

A

Andrus

How to create select columns list dynamically in DLinq ?

I want to create something like

Console.WriteLine("Enter list of columns to return, separated by commas:");
string list = Console.ReadLine();

var q = from c in Db.Customers
where c.Location=="London"
select list;

Andrus.
 
J

Jon Skeet [C# MVP]

Andrus said:
How to create select columns list dynamically in DLinq ?

I want to create something like

Console.WriteLine("Enter list of columns to return, separated by commas:");
string list = Console.ReadLine();

var q = from c in Db.Customers
where c.Location=="London"
select list;

You could build up the expression tree manually for the Select part -
it's unlikely to be *hugely* complicated to do. Mostly a case of seeing
what happens based on other queries.

It's probably easiest to see what's going on by converting the query
expression into its consituent method calls, however - you'll have to
do that anyway, at some point.
 
A

Andrus

Jon,
You could build up the expression tree manually for the Select part -
it's unlikely to be *hugely* complicated to do. Mostly a case of seeing
what happens based on other queries.

It's probably easiest to see what's going on by converting the query
expression into its consituent method calls, however - you'll have to
do that anyway, at some point.

Thank you.
I looked into MS Dynamic Linq library but havent found such function ( it
shows only how to build where clauses dynamically like Mark dynamic query
extensions library)

Where to find any sample for this ?

I want that generated SQL SELECT statement retrieves only selected columns
from database to save bandwidth and allows to update those columns
when I convert query to list and change list members.

Is this possible in Linq ?

Or should I create linq entity object containing only desired properties in
the fly and use this object? Is this possible ?

Or is it simpler to pass queries as ADO .NET SELECT statement strings and
stop trying it in Linq ?
I have no idea how to create updates in this case: it seems that I must
create UPDATE statements manually.

Which is best solution ?

Andrus.
 

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