views:

353

answers:

1

3003 is the exact version I think. Anyway, I have the below code (using ActiveRecord) for creating 2 new entities, deleting any that have the same "Stamp1" and "Stamp2" values, and then I want to insert everything in my List. I cannot tell if the code is efficient for the delete, and I have no idea how to insert everything new from a list into a batch. With v2.x I used "SaveAll" but I don't understand the equivalent functionality in 3. Help!

List<MyEntity> EntsList  = new List<MyEntity>();

MyEntity myEntA = new MyEntity();
myEntA.Stamp1 = Convert.ToDateTime( "1/1/1989" );
myEntA.Stamp2 = Convert.ToDateTime( "1/1/1990" );
EntsList.Add( myEntA );

MyEntity myEntB = new MyEntity();
myEntB.Stamp1 = Convert.ToDateTime( "1/1/1989");
myEntB.Stamp2 = Convert.ToDateTime( "1/1/1990" );
EntsList.Add( myEntB );

for( int d=0 ; d < EntsList.Count ; d++ )
{
   MyEntity delEnt = 
MyEntity .SingleOrDefault ( x => x.Stamp1== EntsList[0].Stamp1 && x.Stamp2== EntsList[0].Stamp2);
delEnt.Delete();
}
for( int d=0 ; d < EntsList.Count ; d++ )
{
   how do I insert everything sequentially or all in one batch?
}

Thanks. This basic stuff is kind of frustrating, all responses appreciated!

+2  A: 

You can use the Add method of the repository to add an IEnumerable collection of objects and this will add all of your objects in one BatchQuery. So you should be able to do something like:

SubSonicRepository<MyEnitity> repo = new SubSonicRepository<MyEntity>(new MyDB());
repo.Add(EntList);
Adam
But I'm doing ActiveRecord so that won't work, right?
ScSub
You still get all the repository functionality with ActiveRecord so yes it should work.
Adam