With CodeSmith 4.0 out the door, i've finally been able to have to some time to finish this. And for being so patient with us, I added a nice treat. There's one problem with composite primary keys on m2m that i'm trying to fix right quick before I post it.
So this is what it looked like before.
LeftTable left = new LeftTable();
left.LeftColumnName = "MyLeftName2";
RightTable right = new RightTable();
right.RightColumnName = "MyRightName2";
RightTable right2 = new RightTable();
right2.RightColumnName = "MyRightName3";
RightTable right3 = new RightTable();
right3.RightColumnName = "MyRightName4";
left.RightTableCollection_From_RightLeftJunction.Add(right);
left.RightTableCollection_From_RightLeftJunction.Add(right2);
left.RightTableCollection_From_RightLeftJunction.Add(right3);
RightLeftJunction both = new RightLeftJunction();
both.LeftColumn1PKSource = left;
both.RightTablePKSource = right;
RightLeftJunction both2 = new RightLeftJunction();
both2.LeftColumn1PKSource = left;
both2.RightTablePKSource = right2;
RightLeftJunction both3 = new RightLeftJunction();
both3.LeftColumn1PKSource = left;
both3.RightTablePKSource = right3;
left.RightLeftJunctionCollection.Add(both);
left.RightLeftJunctionCollection.Add(both2);
left.RightLeftJunctionCollection.Add(both3);
using (TransactionManager tm = DataRepository.Provider.CreateTransaction())
{
tm.BeginTransaction();
DataRepository.LeftTableProvider.DeepSave(tm, left);
tm.Commit();
}
Now, there's no need if you don't want to create the junction entities. The deep save method will automtically check the source objects and see if they exist or not, and create them if they do not exist.
So this becomes:
LeftTable left = new LeftTable();
left.LeftColumnName = "MyLeftName2";
RightTable right = new RightTable();
right.RightColumnName = "MyRightName2";
RightTable right2 = new RightTable();
right2.RightColumnName = "MyRightName3";
RightTable right3 = new RightTable();
right3.RightColumnName = "MyRightName4";
left.RightTableCollection_From_RightLeftJunction.Add(right);
left.RightTableCollection_From_RightLeftJunction.Add(right2);
left.RightTableCollection_From_RightLeftJunction.Add(right3);
using (TransactionManager tm = DataRepository.Provider.CreateTransaction())
{
tm.BeginTransaction();
DataRepository.LeftTableProvider.DeepSave(tm, left);
tm.Commit();
}
This has been tested with a few databases that I have, but it would be great if you guys could give it a spin.
I've changed the way the internals of the DeepSave work as well, they don't work off the keys and properties names anymore. They just use a WeakReference to track if the collection or entity has been loaded. I have not implemented this on the deep load just yet, wanted to verify all was well with DeepSave before I stuck my head in DeepLoad. Should not be that difficult to implement.
Robert Hinojosa
-------------------------------------
Member of the Codesmith Tools, .netTiers, teams
http://www.nettiers.com-------------------------------------