DbUpdateException with entities that do not expose foreign key properties

半世苍凉 提交于 2019-12-05 04:02:32

I feel really dumb right now. After writing up this careful question, it's now obvious.

The Person I am testing with already exists, and already has a User association with a different User.Name. This is why user is coming up null. Setting the Person.User property to a new User is causing the old User to be put in the Deleted state. Doh.

Sorry to have wasted your time. I'll leave the question up unless it's agreed it would be better to delete it.

Make sure you have the relationship defined in your mapping (Entity Type Configuration)

For example:

this.HasRequired(t => t.QuoteResponse).WithMany(t => t.QuoteResponseItems).HasForeignKey(d => d.QuoteResponseID);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!