Asked By R M
09-Feb-10 02:03 PM

Hiya!
I'm trying to do a select on a table where my column names that I select are built off a comma delimited list that I built (this works just fine and produces results like [Field1],[Field2],[Field3] and so on).
So I decided to use the DynamicLinq libraries that MS put out (http://msdn.microsoft.com/en-us/vcsharp/bb894665.aspx) that allow for such operations.
My select query is like this:
dc is my data context
var results =
dc.uf_GetTable(lastUpdated, DateTime.Now).
Where(uf => uf.TableFieldValue.Equals("I")).
Select("new(@0)", dc.ColumnNames<TableName>());
dc.ColumnNames<TableName>() is where I built the list of columns that I want on the select. Reason I'm doing this is because it changes
The dynamic select is as follows:
public static IQueryable Select(this IQueryable source, string selector, params object[] values)
{
if (source == null) throw new ArgumentNullException("source");
if (selector == null) throw new ArgumentNullException("selector");
LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, null, selector, values);
return source.Provider.CreateQuery(
Expression.Call(
typeof(Queryable), "Select",
new Type[] { source.ElementType, lambda.Body.Type },
source.Expression, lambda));}
So I need help figuring out why I keep getting the returned value for my var results as:
SELECT NULL AS [EMPTY]
FROM [dbo].[uf_TableName](@p0, @p1) AS [t0]
WHERE [t0].[TableFieldValue] = @p2
System.Linq.IQueryable {System.Data.Linq.DataQuery}
It SHOULD say:
SELECT [Field1], [Field2], [Field3]
FROM ...
Any clue what I'm doing wrong here? Tips are totally welcome :)