I'm having trouble with following EF lambda expressions.
partial void StatusCallBackRequired_PreprocessQuery(ref IQueryable<PatientsTelephoneFollowupDetail> query)
{
var newList = PatientsTelephoneFollowupDetails.OrderBy(x => x.Id).ToList();
query = query.Where(p => p.PatientsMasterItem.PatientsTelephoneFollowupDetail.OrderByDescending(c => c.Id).FirstOrDefault(c => c.Status == "7") != null);
}
The error is:
'Microsoft.LightSwitch.IOrderedDataServiceQueryable' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'Microsoft.LightSwitch.IOrderedDataServiceQueryable' could be found (are you missing a using directive or an assembly reference?)
I have already included system.linq namespace.
EDIT:(the results based on D Stanley code)
The sample data can be found below and I'm looking to retrieve the highlighted record
However the current output is
Changing query to query.select returns only one record but it's is the wrong record.
Microsoft.LightSwitch.IOrderedDataServiceQueryable
? Does it extent IEnumerable
? Or, does it have any extends method ToList
? If does, you must using
the namespace that contains the extends method - Kirin Yao 2012-04-05 04:08
Couple of things to try:
cast to IEnumerable<T>
:
var newList = ((IEnumerable<PatientsTelephoneFollowupDetail>)PatientsTelephoneFollowupDetails.OrderBy(x => x.Id)).ToList();
Initialize the list from the query result:
var newList = new List<PatientsTelephoneFollowupDetail>(PatientsTelephoneFollowupDetails.OrderBy(x => x.Id)));
EDIT
Looks like LightSwitch doesn't implement IEnumerable<T>
. Two more things to try:
Assuming it implements IEnumerable
, use IEnumerable.Cast<T>()
:
var newList = new List<PatientsTelephoneFollowupDetail>(
PatientsTelephoneFollowupDetails.OrderBy(x => x.Id)
.Cast<PatientsTelephoneFollowupDetail>()
);
brute force:
var newList = new List<PatientsTelephoneFollowupDetail>();
foreach(var item in PatientsTelephoneFollowupDetails.OrderBy(x => x.Id))
newList.Add(item);
Unable to cast object of type 'Microsoft.LightSwitch.ServerGenerated.Implementation.QueryImplementation
1[LightSwitchApplication.PatientsTelephoneFollowupDetail]' to type 'System.Collections.Generic.IEnumerable1[LightSwitchApplication.PatientsTelephoneFollowupDetail]'.
user1213055 2012-04-05 04:20
Error 1 The best overloaded method match for 'System.Collections.Generic.List<LightSwitchApplication.PatientsTelephoneFollowupDetail>.List(System.Collections.Generic.IEnumerable<LightSwitchApplication.PatientsTelephoneFollowupDetail>)' has some invalid arguments
Error 2 Argument 1: cannot convert from 'Microsoft.LightSwitch.IOrderedDataServiceQueryable<LightSwitchApplication.PatientsTelephoneFollowupDetail>' to 'System.Collections.Generic.IEnumerable<LightSwitchApplication.PatientsTelephoneFollowupDetail>'
user1213055 2012-04-05 04:20
FirstOrDefault()
, for example - D Stanley 2012-04-05 13:58
You need to find the definition of this type: Microsoft.LightSwitch.IOrderedDataServiceQueryable
Once you've found it, confirm:
Does it implement IEnumerable<T>
? If so, your code can't reach System.Linq.Enumerable
. You say you are using System.Linq, so make sure your project is referencing System.Core.dll
.
If not, does it implement IEnumerable
? If so, you can write a foreach
loop and add each item to a List<T>
that you make.
If not, examine the properties. There is usually some way to get at the something you can write a loop against.