user776676
user776676

Reputation: 4385

LINQ: LinqDataSource How to do column Select in codebehind?

<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    Select="new(Key as ProductCategory, 
            Average(Price) as AvePrice)"
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>

Somehow my Select in .aspx file (as seen above) is not working: all columns are returned in the query result. So I will try to do that in code behind.

How do I perform the selection of the 2 fields in my LinqDataSource1_Selecting ()? Thanks.

Upvotes: 1

Views: 1354

Answers (3)

Gert Arnold
Gert Arnold

Reputation: 109282

You forgot the GroupBy="ProductCategory".

Upvotes: 1

Esi
Esi

Reputation: 395

for example:

//notice: condition is sample

int ave ;

Queryable<Object> IQ = ContextTypeName.TableName.Where(x=>x.Price <= ave);

OR

var Query = FROM objectNameSeleted IN ContextTypeName.TableName
            WHERE (your condition) SELECT objectNameSeleted 

Upvotes: 1

SPillai
SPillai

Reputation: 187

List<object> Products = (from p in ExampleDataContext.Products
                     where CONDITION
                     select p).ToList<object>();

Upvotes: 1

Related Questions