Merging two dOOdads

All your dOOdad needs ...

Merging two dOOdads

Postby sbc on Mon Apr 23, 2007 11:10 am

I have an ASP.NET page, which display a table of results bound to a dOOdad (it may be sorted, or filtered by a query etc).

However, in some cases (i.e. when a record has been edited or added), I want a particular record to be the first one.

Code: Select all
// dOOdad without the edited record
MydOOdad d1 = new MydOOdad();
d1.Where.RecordID.Value = 199;
d1.Where.RecordID.Operator = WhereParameter.Operand.NotEqual;
d1.Query.AddOrderBy(MydOOdad.ColumnNames.RecordID, WhereParameter.Dir.ASC);
d1.Query.Load();

// dOOdad with the edited record(s) only
MydOOdad d2 = new MydOOdad();
d2.Where.RecordID.Value = 199;
d2.Query.Load();

// the doodad to be bound to the repeater
MydOOdad BindMe = new MydOOdad();
// what to do here?
BindMe = d2 + d1;

Can this be done, without resorting to looping through both dOOdads and adding each entry to another one?
User avatar
sbc
Expert
 
Posts: 446
Joined: Sat Apr 03, 2004 6:10 am
Location: North East Lincolnshire, England

Postby mike.griffin on Mon Apr 23, 2007 1:21 pm

There is nothing built into dOOdads to do that, you would have to use the DataTable of one to dump rows into another.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby sbc on Mon Apr 23, 2007 2:46 pm

This is what worked for me:

Code: Select all
public static MydOOdad MergedOOdad(MydOOdad first, MydOOdad second)
{
   first.DataTable.Merge(second.DataTable, true);
   return first;
}

Code: Select all
// dOOdad without the edited record
MydOOdad d1 = new MydOOdad();
d1.Where.RecordID.Value = 199;
d1.Where.RecordID.Operator = WhereParameter.Operand.NotEqual;
d1.Query.AddOrderBy(MydOOdad.ColumnNames.RecordID, WhereParameter.Dir.ASC);
d1.Query.Load();

// dOOdad with the edited record(s) only
MydOOdad d2 = new MydOOdad();
d2.Where.RecordID.Value = 199;
d2.Query.Load();

// the doodad to be bound to the repeater
MydOOdad BindMe = MydOOdad.MergedOOdad(d2, d1);
User avatar
sbc
Expert
 
Posts: 446
Joined: Sat Apr 03, 2004 6:10 am
Location: North East Lincolnshire, England

Postby mike.griffin on Mon Apr 23, 2007 3:49 pm

Excellent approach, this is why I like using ADO.NET underneath the hood, thanx for posting the solution. Perhaps you should call the method \"Combine\" ? Sheeze, I had to tinker, sorry ...
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby sbc on Mon Apr 23, 2007 4:11 pm

Combine does sound more logical (although there is a remote chance you may have a column with that name). With a little modification, it could take an array of dOOdads objects I think.
User avatar
sbc
Expert
 
Posts: 446
Joined: Sat Apr 03, 2004 6:10 am
Location: North East Lincolnshire, England

Postby mike.griffin on Tue Apr 24, 2007 11:42 am

You know, we have been looking for somebody to take over the dOOdads project :wink:
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN


Return to dOOdads - MyGeneration's .NET Architecture

Who is online

Users browsing this forum: No registered users and 0 guests

cron