how to get typedlist for EF5 do a count

Posts   
 
    
vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 09-May-2013 15:57:20   

I am exploring EF5 using llblgen designer, and in this case trying to put a count in the aggregate function of the Typed List in the designer.

I remember when using llblgen generated code, we had to supply the group by clause to the adapter.

So how do I go about getting the count for EF5 generated code.

I looked through the DbContext llblgen generated,


public IQueryable<NumUsersInRolesTypedListRow> GetNumUsersInRolesTypedList()
{
  var current0 = this.Roles;
  var current1 = from role in current0
           join userFacilityRole in this.UserFacilityRoles on role.Id equals userFacilityRole.Role.Id into joinresult_1
           from userFacilityRole in joinresult_1.DefaultIfEmpty()
           select new {userFacilityRole, role };
  return current1.Select(v=>new NumUsersInRolesTypedListRow() { Id = v.role.Id, Name = v.role.Name, NumUsers = v.userFacilityRole.UserIdFk } );
}

I had put a count aggregate function for the field UserIdFk in the designer.

I would have imagined the code would have looked something like this


var q = from r in db.Roles
    join ufr in db.User_Facility_Role on r.ID equals ufr.Role_ID_FK
    into rst select new { r.ID, r.Name, Num_Users = rst.Count() };

What am I missing?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2013 19:11:56   

Which version of the Designer are you using? (release date)

vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 09-May-2013 19:15:07   

Walaa wrote:

Which version of the Designer are you using? (release date)

Version: 3.5 Final Release On: January 17th, 2013

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2013 19:43:24   

Could you please share (attach) a repro llblgen proj file?

vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 09-May-2013 19:48:35   

Walaa wrote:

Could you please share (attach) a repro llblgen proj file?

Attached. Thanks for looking into this.

Attachments
Filename File size Added on Approval
PPSAdmin.zip 3,584 09-May-2013 19:48.50 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2013 20:00:57   

Reproduced. Will get back to you a.s.a.p.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 10-May-2013 10:32:09   

These aggregates are ignored for EF, L2S and NHibernate, as for all aggregates except Count, it will require a different query than the one generated.

The problem is that in linq, if you define two fields with Sum for example, the query requires a group by, but that's not definable in the designer, so we ignore the aggregates, as is described here: http://www.llblgen.com/documentation/4.0/Designer/hh_goto.htm#Functionality%20Reference/TypedListEditor_FieldsTab.htm

It's not really a big deal in the case of EF, L2S and NHibernate as they define a query, so it's easy to define a new projection on this query with the aggregates you want, with the groupby you want and then fetch the objects with the query you want. The LLBLGen Pro runtime framework doesn't generate queries for typedlists, so the aggregates have to be in the generated code, hence the designer feature.

Frans Bouma | Lead developer LLBLGen Pro
vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 10-May-2013 13:15:53   

Excellent, thanks.