Returning a collection of "Uniques"

Posts   
 
    
Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 28-Oct-2004 18:49:57   

Heya,

What I need is a way to return a list of only the unique values in a given field, for a given collection.

That may have been vague, so here is an example of what I mean:

I have a collection of sales receipts for a one month period and want to return a list of customers who made a purchase within that period. Customer, obviously, would be a field within the receipts collection, and I can't just return the customer field of each record in my collection, because some customers may have made multiple purchases...

Any ideas? And sorry for dumbing it down so much...

Thanx in advance.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Oct-2004 21:02:20   

You want a list with a single field (customerid) or a list of customer objects? The first can be made with a dynamic list (see documentation on typedlists) and a filter, and using the typedlist fetch logic you can specify if you want duplicates or not. When you want objects, you can simply filter on the customer objects, as these will always be unique.

Frans Bouma | Lead developer LLBLGen Pro
Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 29-Oct-2004 17:26:00   

Hmm, thats not quite what I mean, let me try again:

I have a table with the following fields: Date, Customer and TotalBill, where the customer field is a reference into another table called Customers, and the other two fields are just the date of teh transaction and the total amount charged to the customer.

At the end of the month, I want to generate a statement for each customer who has made at least one purchase in the previous 30 days. I want to generate one statement and one statement only, and just have a list of all that customers transacations (if they have had more than one) on it.

So my question is, is there any build in functionality in LLBLGEN to allow me get a list/array of all the customers who have at least one record within the collection retrieved via selectfilters created upon date (ie Table.Date > Now minus 30 days and Table.Date <= Now)?

I hope that was a little more clear. All I really want is an array (or something similar) of all the Customers whose names appear at least once within my retrieved collection...

Thanx again, Sean

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Oct-2004 19:22:05   

I illustrate it using SelfServicing.


CustomerCollection customers = new CustomerCollection();
IRelationCollection relations = new RelationCollection();
relations.Add(CustomerEntity.Relations.SalesReceiptEntityUsingCustomer);
IPredicateExpression filter = new PredicateExpression();
filter.Add(//... add your 2 date compare predicates here)

customers.GetMulti(filter, relations);

So it basicly does an inner join with salesreceipt. This will only keep the customers which have 1 record in that table, and you filter out the rows which have a salesreceipt outside the month range.

Because you fetch objects, these are always unique, so you can then just traverse the collection.

Frans Bouma | Lead developer LLBLGen Pro