Prevent Entity Framework to Insert Values for Navigational Properties

后端 未结 4 2083
终归单人心
终归单人心 2020-12-07 15:52

I am working on a WPF application using Entity Framework 4.0. When I tried to save the object, I got a primary key exception, but the primary key is an AutoIncremented field

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 16:44

    In my case I had collections that were manually populated from a different context (different database). In order to prevent my main context from trying to save these collections I ended up adding

    [NotMapped, NotNavigable]
    

    annotations to the property definitions.

提交回复
热议问题