1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public static void DataAccessInsert(categ_piece categ_piece)
{
using (PannikausDataContext db = DbManager.DataContext)
{
try
{
db.categ_piece.InsertOnSubmit(categ_piece);
db.SubmitChanges(ConflictMode.ContinueOnConflict);
}
catch (ChangeConflictException)
{
db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges, true);
db.SubmitChanges();
}
catch (SqlException sqlException)
{
if (sqlException.Number == 547)
{
throw new ForeignKeyViolationException(sqlException.Message, sqlException.InnerException);
}
if (sqlException.Number == 2601 || sqlException.Number == 2627)
{
throw new UniqueKeyViolationException(sqlException.Message, sqlException.InnerException);
}
}
}
} |
Partager