tags:

views:

744

answers:

1

What is the difference between: .Save();
.Add(); .Update():

+9  A: 

You don't mention which templates you're using (I'm going to assume ActiveRecord), but as a general rule:

  • Save will insert if the object IsNew==true or otherwise it will update.
  • Add will always insert a new record.
  • Update will only update an object with IsNew==false and will fail if there is no corresponding record in the db for the instance.
John Sheehan
Thanks John. Yes, I am using Active Records.BTW, I read a bit of your "How I Use SubSonic" article but noticed it 's for Subsonic 2. Now, this is my first time using Subonic (v 3) and looking for some advise on how to layer my application (DAL, BLL, UI). I for sure don't want to expose the DAL to my UI. Any tips?
Shuaib
Don't use ActiveRecord ;) I would start by familiarizing yourself with the LinqTemplates. It makes it a lot easier to separate your layers. That's a good idea for another blog post though...bringing the 2.x stuff up to speed on 3.
John Sheehan
Thanks John.I will read about LinqTempaltes. I think it is time for a new blog post.
Shuaib
What's the difference between ActiveRecord and LinqTemplates?
Jon
The LinqTemplates use the Repository pattern which makes it easier to keep all your data access code in one place (far from the UI)
John Sheehan
John,any example of how LinqTempaltes would make things easier?
Shuaib