Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34180

Using Linq to Sql join in generic handler

I have some query that is working correctly but I just copied exact code without any modification to a new Generic Handler (ashx) file and I'm getting an error. This is the code:

 System.Collections.Generic.List<ChartPrice> ChartPrices =
 new System.Collections.Generic.List<ChartPrice>();
 using (DatabaseDataContext db = new DatabaseDataContext())
    {
       ChartPrices = (from p1 in db.Prices
                     join p2 in db.Prices on p1.Date equals p2.Date
                     where p1.ProductId == -1 && p1.Id != p2.Id
                     orderby p1.Date descending
                     select new ChartPrice {
                     Price1 = p1.Amount.ToString(),
                     Price2 = p2.Amount.ToString(),
                     Date = (DateTime)p1.Date })
                     .Take(30).ToList();
    }

And this is the error:

Error 33 Could not find an implementation of the query pattern for source type 'System.Data.Linq.Table'. 'Join' not found. Are you missing a reference or a using directive for 'System.Linq'?

I get a red line under the first db.Prices (ChartPrices = (from p1 in db.Prices)

enter image description here

Is there something I can do to use this code in generic handler file?

Upvotes: 1

Views: 256

Answers (1)

Callum
Callum

Reputation: 725

The base class does not include/use System.Linq so linq expressions were not applicable for usage in code.

Note: this was solved in the comments, this answer is just for those that did not read the comments.

Upvotes: 2

Related Questions