I was getting following error when I was trying to connect the WCF RIA Services using XAML.
Microsoft JScript runtime error: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ServiceModel.DomainServices.Client.DomainException: An error occurred while loading data through the 'MyMethodNameQuery' query on DomainContext of type 'MyContext' and the error was not handled. If this error is expected, then you must handle the LoadedData event on the DomainSource and call LoadedDataEventArgs.MarkErrorAsHandled() to avoid this exception.
Load operation failed for query 'MyMethodNameQuery'. The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. ---> System.ServiceModel.DomainServices.Client.DomainOperationException: Load operation failed for query 'MyMethodNameQuery'. The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
--- End of inner exception stack trace ---
at System.Windows.Controls.DomainDataSource.RaiseLoadedData(LoadedDataEventArgs e)
at System.Windows.Controls.DomainDataSource.MyContext_Loaded(LoadedDataEventArgs e, LoadContext loadContext)
at System.Windows.Controls.DomainDataSource.LoadData_Callback(LoadOperation loadOperation)
at System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
at System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.MyContext.<>c__DisplayClass1b.<Load>b__17(Object )
Solution: If you investigate this error, you will notice that it is asking for the OrderBy method, so I added OrderBy method into the MyMethodNameQuery method (along with the Entity layer property) and I resolved this error.
public IQueryable<PersonalDetail> MyMethodNameQuery()
{
return this.ObjectContext.MyTableNames.OrderBy(p => p.FirstName);
}
Hope this will be helpful.
Thanks!
Regards,
Sheo Narayan
http://www.dotnetfunda.com