New Posts New Posts RSS Feed: Basic Projections
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Basic Projections

 Post Reply Post Reply
Author
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post Topic: Basic Projections
    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!

 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
jkowalski View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Jul-2010
Location: Bellingham, WA
Posts: 8
Post Options Post Options   Quote jkowalski Quote  Post ReplyReply Direct Link To This Post 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.



Edited by jkowalski - 06-Jul-2010 at 9:33am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down