Domanda

I have the following query

var query = (from b in db.StudentProgressPerDay
             where b.Student.Equals(InputStudent)
             orderby b.Date
             select b);

and the following command which is runs ok

var dates = query.Select(x => EntityFunctions.DiffDays(query.Min(y => y.Date), x.Date));

When I add a toList() command at the end, the aforementioned function does not work but instead it gives an exception

An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code

È stato utile?

Soluzione

EntityFunctions is specific to Linq-to-Entities. ToList creates a regular List, so any queries on the list will be Linq-to-Objects from that point.

Try the following:

var query = (from b in db.StudentProgressPerDay
                         where b.Student.Equals(InputStudent)
                         orderby b.Date
                         select b).ToList();

var dates = list.Select(x => (x.Date - query.Min(y => y.Date)).Days);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top