none
LINQ2SQL SubmitChanges throwing Object reference not set to an instance of an object exception RRS feed

  • Question

  • DataContext Submit changes is trowing the error when tries to udate the record.

    System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Data.Linq.Mapping.MetaAccessor`2.SetBoxedValue(Object& instance, Object value)
       at System.Data.Linq.ChangeProcessor.ClearForeignKeysHelper(MetaAssociation assoc, Object trackedInstance)
       at System.Data.Linq.ChangeProcessor.ClearForeignKeyReferences(TrackedObject to)
       at System.Data.Linq.ChangeProcessor.PostProcessUpdates(List`1 insertedItems, List`1 deletedItems)
       at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
       at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
       at System.Data.Linq.DataContext.SubmitChanges()

    Those update operation is very simple master detail scenario. Finding master record and delete all child records. Then Add few child record then submit changes. Then it is throwing error.

    If I only add child records instead, it is not throwing any error.

    Not sure the reason for this.

    N.B: Here we are not directly using LINQ2SQL datacontext, reather we are using a custome wrapper on top of it to create light weight db user wrapper similar to NHibernate.

    Thursday, May 24, 2012 10:21 AM

Answers

  • Sorry about the information is not enough, actually I thought at the begining that This is a common general mistake I was doing. But it is not so.

    The whole data layer or I should say ORM was written by party developer, And all the entity and their relationship was also generated by a tool or may be manually, not sure (But that was not generated by Visual studio). And they have written a custom data access layer on top of this. Other than the Operation I was performing was very simple. Just adding master record and updating detail records. And then session.submitchanges - thats all. It was throwing error. It was also not possible to provide whole ORM layer code.

    But the problem was in the Entity, the master and detail entity were not associated properly. Didn't expect that. I think, In this kind of problem,  if the ORM layer is not autogenerated, we should check once the entity carefully (if it is not auto generated). We should also tally with the database tables.

    But anyway, Thanks all of you for posting the answer.

    Wednesday, May 30, 2012 11:04 AM

All replies

  • Hi, 

    The information you provided is so abstract we cant see what is going on. We can see problem better only if you provide more information.

    What is InnerException is showing, InnerException will give more details. In general "Object reference not set to an instance of an object" will be thrown when object is null.  


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Thursday, May 24, 2012 10:33 AM
  • Hi SouvickM,

    Welcome to the MSDN Forum.

    As Kris said, it is hard to find the root cause based on your current information. Please show us more details.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 25, 2012 6:01 AM
    Moderator
  • Sorry about the information is not enough, actually I thought at the begining that This is a common general mistake I was doing. But it is not so.

    The whole data layer or I should say ORM was written by party developer, And all the entity and their relationship was also generated by a tool or may be manually, not sure (But that was not generated by Visual studio). And they have written a custom data access layer on top of this. Other than the Operation I was performing was very simple. Just adding master record and updating detail records. And then session.submitchanges - thats all. It was throwing error. It was also not possible to provide whole ORM layer code.

    But the problem was in the Entity, the master and detail entity were not associated properly. Didn't expect that. I think, In this kind of problem,  if the ORM layer is not autogenerated, we should check once the entity carefully (if it is not auto generated). We should also tally with the database tables.

    But anyway, Thanks all of you for posting the answer.

    Wednesday, May 30, 2012 11:04 AM