1
<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.

user776676
  • 4,265
  • 13
  • 58
  • 77

3 Answers3

1
List<object> Products = (from p in ExampleDataContext.Products
                     where CONDITION
                     select p).ToList<object>();
SPillai
  • 177
  • 3
  • 7
  • 20
1

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 
Esi
  • 389
  • 5
  • 14
1

You forgot the GroupBy="ProductCategory".

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291