InvalidOperationException when calling SaveChanges in .NET Entity framework

后端 未结 8 1231
小蘑菇
小蘑菇 2020-12-03 17:22

I\'m trying to learn how to use the Entity framework but I\'ve hit an issue I can\'t solve. What I\'m doing is that I\'m walking through a list of Movies that I have and ins

8条回答
  •  时光取名叫无心
    2020-12-03 18:11

    last time I tried the following code and I said it is working fine

    bs.SuspendBinding();
    Data.SaveChanges();
    bs.ResumeBinding();
    

    The important things which I wana tell you today are that:

    1- if we use the above code to suspend binding we have to do more code to fix a lot of scenarios like index lost in the collections and the master detail bindings

    2- if we use the following code instead of the above code we will see the exception gone and every thing will be ok where no need to write more code

            Data.SaveChanges(System.Data.Objects.SaveOptions.None);
    

    I hope this solves your similar problems

    thank you friends

提交回复
热议问题