Print Page | Close Window

Basic Projections

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1942
Printed Date: 21-Apr-2026 at 12:19pm


Topic: Basic Projections
Posted By: jkowalski
Subject: Basic Projections
Date Posted: 06-Jul-2010 at 9:30am

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.




Replies:
Posted By: kimj
Date Posted: 06-Jul-2010 at 12:24pm
I'm afraid that the EntityQueryPagedCollectionView doesn't currently support anonymous types.   This problem was identified in DevForce 2009, but not yet fixed either there or in DevForce 2010.  We will be making some major changes to the EntityQueryPagedCollectionView and ObjectDataSource in a later release this year.  Until then, the workaround is to stick with queries returning an entity type.


Posted By: jkowalski
Date Posted: 06-Jul-2010 at 12:31pm
WHAT!?
 
One of the main reasons that we are looking at you guys is the ability to get only the data we need, and control that request on grid population with user settings (users can chose the columnes they want displayed).
 
Is there a work around here?
 
Thanks.


Posted By: kimj
Date Posted: 06-Jul-2010 at 1:04pm
Projections are supported everywhere within DevForce except the EntityQueryPagedCollectionView. 
 
The only workaround when using the EntityQueryPagedCollectionView is the one I mentioned.   We will look at the possibility of fixing this in the next release, due later this month.


Posted By: jkowalski
Date Posted: 06-Jul-2010 at 1:15pm
That would be great!
 
I have another work around.
 
Projecting into a known type:
 
On the Server:

[DataContract]

public partial class Account : IKnownType

{

    [DataMember] public string AccountName { get; set; }

    [DataMember] public string AccountType { get; set; }

    [DataMember] public string EmailAddress { get; set; }

}

 
On The Client

public EntityQuery GetQuery()

{

    var query = Globals.SMEntityManger.SM_Accounts

        .Where(e => e.AccountName.StartsWith("a"))

        .Select(e => new Trident.Server.View.Account { AccountName = e.AccountName,

        AccountType = e.AccountType });

 

    return (EntityQuery)query;

}

 

 

I will keep my hears open for the changes.

 

Thanks!

 



Print Page | Close Window