Capturing Sql Errors on Save

2 posts, 0 answers
  1. David
    David  avatar
    66 posts
    Member since:
    Aug 2010

    Posted 17 Mar 2012 Link to this post


    I have setup an OpenAccess Model and I'm currently testing a few things. I'm using a WinForms app I have added a RadGrid on the form and set the datasource 

    this.radGridView1.DataSource = Context.Employees.ToList<Employee>();

    I am then using the following events to capture Inserts/Deletes

    this.radGridView1.UserAddedRow += new Telerik.WinControls.UI.GridViewRowEventHandler(radGridView1_UserAddedRow); 
    this.radGridView1.UserDeletingRow += new Telerik.WinControls.UI.GridViewRowCancelEventHandler(radGridView1_UserDeletingRow);

    This all works ok i can add/remove/update values

    The issue I'm having is I have a Unique Index constraint on the e-mail column, if I try to add a employee with the same e-mail address then the SaveChanges will throw an exception. No data changes are then saved into the database but this is not flagged in then application  

    How should I be handling these sort of errors?

  2. Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 21 Mar 2012 Link to this post

    Hi David,

    You could use the OpenAccessContextBase.Refresh(RefreshMode mode, IEnumerable entities) method to refresh the state of the persistent capable objects collection when the changes are not persisted to the database.

    If any other questions arise, do not hesitate to contact us back.

    Damyan Bogoev
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
  3. DevCraft banner
Back to Top