I must be missing something silly here. We are new to projections and LINQ.
I’m trying to execute a Query in the EntityQueryPagedCollectionView class. I’m using this object as a DataContext for the DataGrid and the DataPager. When I use a query directly from the EntityManager all is well. However, when I try to use a projection all hell breaks lose. I have tried structuring the Query in many ways. From some of the limited information I found about this on the forum, here is my latest attempt.
public void RefreshData()
{
EntityQueryPagedCollectionView pcv = new EntityQueryPagedCollectionView(
GetQuery(), // Source of data
pgr.PageSize, // Page size
pgr.PageSize, // Load size - no lookahead caching here
true, // Whether to defer the load
false); // Whether to add primary key to sort columns
^^^^ERROR OCCURES AT CONSTRUCTOR^^^^^
pcv.SortDescriptions.Add(new SortDescription("AccountName", ListSortDirection.Ascending));
pcv.Refresh();
DataContext = pcv;
}
public EntityQuery GetQuery()
{
var query = Globals.SMEntityManger.SM_Accounts //The EntityManger lives as a global static object
.Where(e => e.AccountName.StartsWith("a"))
.Select(e => new {e.AccountName, e.AccountType}); //Atempting projection
return (EntityQuery)query;
}
GENERATES: {System.MethodAccessException: Attempt by method 'IdeaBlade.Core.TypeFns.ConstructGenericInstance(System.Type, System.Type[])' to access method 'System.Collections.Generic.List`1<System.__Canon>..ctor()' failed...
Please help! This has been troubling us for 2 days. And I'm totally open to best practice. I’m sure you guys do this all the time.
Edited by jkowalski - 06-Jul-2010 at 9:33am