-1

I'm trying to output a simple calculation to a crystal reports viewer in my WPF application. I'm currently getting "The specified type member 'StockSaleValue' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

Update

Fixed with

 using (CrystalReportsTestEntities db = new CrystalReportsTestEntities())
        {
            var stocks = db.Stocks.ToList().Where(item => item.StockSaleValue > 5);
            report.SetDataSource(stocks);
        }
bucky112
  • 74
  • 1
  • 7
  • Instead of `.ToList()` you should use `.AsEnumerable()` since `.ToList()` iterates through the complete dataset and converts in into a list, where `.AsEnumerable()` just loops lazily through the collection. – Maarten Sep 16 '14 at 13:31
  • When you find a solution, you should post it as a solution. Or, since @Sheridan clearly provided the basis for your answer, you should mark that answer as correct and up-vote it. – Thomas Sep 16 '14 at 13:56

1 Answers1

1

Have you tried something like this?:

using (CrystalReportsTestEntities db = new CrystalReportsTestEntities())
{
    List<Stock> stocks = db.Stocks.Where(item => item.StockSalePrice > 5).ToList();
    report.SetDataSource(stocks);
}
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Yes I've tried that and its still giving me the same error. – bucky112 Sep 16 '14 at 13:26
  • 3
    The issue occurs within the `Where` clause itself. `StockSalePrice` is a calculated client-side property, and cannot be translated to the where clause of the SQL query. The `ToList()` would have to occur before the `Where` clause if the `Stock` class remains as-is. – avanek Sep 16 '14 at 13:27