grouping entities by date of Birth

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 05-Oct-2007 14:28:16   

version 1.0.2005.1 final (self-servicing) VS2005 asp.net 2.0


Hiya,

I need to use a predicate to group together dogs that are born on the same date to the same father.


TListDogTypedList dogs = new TListDogTypedList();
IPredicateExpression filtDog = new PredicateExpression();
filtDog.Add(TblDogFields.fatherId== dogId);
dogs.Fill(0, null, false, filtDog);

So, I now have a list of all dogs who have this father. Now, I have to group these into dogs who were born on the same day...


 IPredicateExpression filtDateOfBirth = new PredicateExpression();
filtDateOfBirth.Add(TblDogFields.DateOfBirth == ??);

hmm, I'm a bit stuck.

Any ideas?

Many thanks,

yogi

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 05-Oct-2007 15:26:35   

I'm not sure what you are trying to do here. With the first code part you create a collection of entities where the father has a specific dogID.

With the second code part I don't know what you are trying to do ...

Am I right that you want a filter on both the FatherID AND the DateOfBirth?

Because then you can just do (used the current date ... ):

TListDogTypedList dogs = new TListDogTypedList();
IPredicateExpression filtDog = new PredicateExpression();
filtDog.Add(TblDogFields.fatherId== dogId);
filtDog.Add(PredicateFactory.CompareValue( TblDogFields.DateOfBirth, ComparisonOperator.Equal, DateTime.Now);
dogs.Fill(0, null, false, filtDog);

You need to change the compare to compare only the datepart and not date with time included ...

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 08-Oct-2007 12:53:20   

hiya.

Ta for the reply.I'm confused by your answer though.Let's say there are 4 dogs with same father... As we know I can filter on the fatherId. So, that's finished.

The issue is that I need to GROUP the dogs by date of birth.

dogId 1 fatherId 5 dateOfBirth 01/01/2005

dogId 2 fatherId 5 dateOfBirth 01/01/2005

dogId 3 fatherId 5 dateOfBirth 01/01/2006

dogId 4 fatherId 5 dateOfBirth 01/01/2006

How do I use a predicate to group dogId 1 + dogId 2 together,

then dogId 3 + dogId 4 together??

many thanks,

yogi

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 08-Oct-2007 14:12:56   

are you trying to sort , filter or get summaries grouped by father and date?

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 08-Oct-2007 14:28:48   

hiya,

I want to filter the list of dogs by fatherId (DONE) I then want to group those dogs by the day that they were born.

Please let me know if I can clarify further.

yogi

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 08-Oct-2007 16:50:57   

this: dogId 1 fatherId 5 dateOfBirth 01/01/2005

dogId 2 fatherId 5 dateOfBirth 01/01/2005

dogId 3 fatherId 5 dateOfBirth 01/01/2006

dogId 4 fatherId 5 dateOfBirth 01/01/2006

would translate into

select dogid, dateofbirth
from   dog
where fatherid = 5
order by dateofbirth

this produces the following result set

dogid dateofbirth
----- -----------
1    1-1-05
2    1-1-05
3    1-1-06
4    1-1-06

you could group in a heirachy, but that must be done in code


dogcollection = result set

datatable birthdays = new datatable("birthdays");
birthdays.columns.add("dateofbirth", typeof(datetime));
birthdays.primarykey = new datacolumn[] { birthdays.columns[0] };

datatable dogs = new datatable("dogs");
dogs.columns.add("dogid", typeof(int));
dogs.columns.add("dateofbirth", typeof(datetime));
dogs.primarykey = new datacolumn[] { dogs.columns[0] };

datarelation relation = new datarelation(birthdays.column[0], dogs.column[1]);

dataset ds = new dataset();
ds.tables.add(birthdays);
ds.tables.add(dogs);
ds.relations.add(relation);

foreach (dog in dogcollection)
{
      if (!birthdays.Find(dog.dateofbirth))
      {
            birthdays.rows.add(new object[] { dog.dateofbirth });
      }

      dogs.add(new object[] { dog.id, dog.dateofbirth });
}

return ds;

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 08-Oct-2007 17:52:56   

hiya Jason,

ta for the help.

I'm having a bit of hassle with creating the relation in code:

DataRelation relation = new DataRelation(birthdays.Columns[0], dogs.Columns[1]);

So I tried to add a relation name:

DataRelation relation = new DataRelation("relation", birthdays.Columns[0], dogs.Columns[1]);
    

But then I get an error that I can't work out.

Cannot create a DataRelation if Parent or Child Columns are not in a DataSet.

Hmm, I'm struggling on this one. Can anyone help?

many thanks,

yogi

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 08-Oct-2007 18:08:08   

add the tables to the dataset and then create the relationship.

dataset ds = new dataset();
ds.tables.add(birthdays);
ds.tables.add(dogs);
ds.relationships.add("bithdays_dogs_FK", birthdays.columns[0], dogs.columns[1]);

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 08-Oct-2007 19:31:21   

I need to use a predicate to group together dogs that are born on the same date to the same father.

TListDogTypedList dogs = new TListDogTypedList();
IPredicateExpression filtDog = new PredicateExpression();
filtDog.Add(TblDogFields.fatherId== dogId);
dogs.Fill(0, null, false, filtDog);

So, I now have a list of all dogs who have this father. Now, I have to group these into dogs who were born on the same day...

IPredicateExpression filtDateOfBirth = new PredicateExpression();
filtDateOfBirth.Add(TblDogFields.DateOfBirth == ??);

Hi yogiberr, could you paste here the sql-query that you want to produce?

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 11-Oct-2007 16:54:45   

hiya folks,

Ta for the help thus far. I'm not too good with group by queries.

At the moment, I'm going to try and do it with the built-in telerik grid functionality. I'll let yous know how I get on :-)

ta,

yogi