Will this safely delete my record?

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-06-18T15:54:30Z Indexed on 2010/06/18 16:03 UTC
Read the original article Hit count: 341

Filed under:
|

I hate these three tables that. Two tables have a many to many relationship and as such it generates a third table.

http://imgur.com/yLKif.png

I'm using Linq-to-SQL and in the .dbml file I've dragged all the folder there to the graphic surface.

Here is the method I'm using to delete an Area safely. Remember that documents are associated to an Area, so I can't just delete it and leave documents hanging.

        ScansDataContext db = new ScansDataContext();

        /// <summary>
        /// Deletes an Area object from the database along with all associations in the database.
        /// </summary>
        /// <param name="area">Area object to save</param>
        public void Delete(Area area)
        {
            db.DocumentAreaRelations.DeleteAllOnSubmit(area.DocumentAreaRelations);
            db.Areas.DeleteOnSubmit(area);
            db.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql