none
Insert being ignored RRS feed

  • Question

  • I am using LINQ to SQL in my 4th project and I have never run across this.  I have used the designer to create my classes and I ran into a problem where a simple created object is not inserting.  I have a logger attached to the DataContext and I never see the insert.  I have checked the change set by calling GetChangeSet before the call to SubmitChanges and it correctly reports one object to insert and it has the correct value.  During the call to SubmitChanges nothing is logged.  After the call to SubmitChanges, the record is not inserted, no exception is thrown, GetChangeSet returns no objects that need changes and ChangeConflicts reports nothing.  Sql Profiler shows no inserts as well.

     

    As a quick test, I created a new table, mapped it and did an insert with it with no problems.  Shouldn't there either be an exception or a change conflict or something?  Has anyone else ever seen this?  It is currently way too much code to post, but I am going to try to water it down to something easily repeatable.

    Tuesday, March 4, 2008 6:24 AM

Answers

  • I need to apologize for posting this.  Another person on the team had put in insert and update partial functions for the DataContext class thinking they would be executed before each action and modify the classes properties before the framework saved the objects.  Unfortunately, these functions were placed in a file with a class with another file, which is why I hadn't noticed them.  Those functions were being called instead of performing the inserts and updates, which is what they are for.  Go figure!

     

    Anyways, this was very exciting.  A definite thing to look for in the future with partial classes.

    Wednesday, March 5, 2008 11:28 PM

All replies

  • Hi,

     

    Certainly does sound strange - any set of easily repeatable scenarios will help us in diagnosing the scenario. Also, please share any of the code where you are adding the entity to the DataContext before calling SubmitChanges, and we can try to zero in on the issue.

     

    Thanks.

    -faisal

     


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, March 5, 2008 12:19 AM
    Moderator
  • I need to apologize for posting this.  Another person on the team had put in insert and update partial functions for the DataContext class thinking they would be executed before each action and modify the classes properties before the framework saved the objects.  Unfortunately, these functions were placed in a file with a class with another file, which is why I hadn't noticed them.  Those functions were being called instead of performing the inserts and updates, which is what they are for.  Go figure!

     

    Anyways, this was very exciting.  A definite thing to look for in the future with partial classes.

    Wednesday, March 5, 2008 11:28 PM