Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> Count aggregate on a view.
 

Pages: 1
Architecture
Count aggregate on a view.
Page:1/1 

  Print all messages in this thread  
Poster Message
JayBee
User



Location:

Joined on:
28-Dec-2006 18:47:54
Posted:
232 posts
# Posted on: 19-Oct-2016 20:27:44.  
I'm using LLBLGen 4.2 SelfServicing.

I have a view Pallet with 4 fields: Code, IdSap, Pallennummer and DateTimeCreated.
I want to have a collection that is the outcome of:

select Code, IdSap, count(distinct Palletnummer) where DateTimeCreated between from and to.

The following is working fine:

            ResultsetFields fields = new ResultsetFields(3);
            fields.DefineField(PalletFields.Code, 0);
            fields.DefineField(PalletFields.IdSap, 1);
            fields.DefineField(PalletFields.Palletnummer, 2, "Pallets");
            fields[2].AggregateFunctionToApply = AggregateFunction.CountDistinct;
            PredicateExpression filter = new PredicateExpression(new FieldBetweenPredicate(PalletFields.DateTimeCreated, from, to));
            SortExpression sorter = new SortExpression(PalletFields.Code | SortOperator.Ascending);
            GroupByCollection gbc = new GroupByCollection();
            gbc.Add(PalletFields.Code);
            gbc.Add(PalletFields.IdSap);
            TypedListDAO dao = new TypedListDAO();
            DataTable results = new DataTable();

I do not think this is the most elegant wayConfused
Isn't it possible to achieve via collection on the view itself, without using the result set?
I also tried QuerySpec but could not get it to work.
How could this be done via QuerySpec?
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14421 posts
# Posted on: 20-Oct-2016 23:01:58.  
You are doing it the right way, as you are aggregating and grouping.
Collections are used to retrieve entities as they exist in the database.

Please post your QuerySpec code trials, and the output.

There is an example here in docs that can give you a clear idea how to aggregate and group in QuerySpec


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.