嵌套属性的 SetModifiedProperty
如何为嵌套属性设置 SetModifiedProperty?换句话说,我有一个实体作者,其实体有一个书籍集合,我只需要更改一个书名。
var existingAuthor = authors.FirstOrDefault(x => x.Id.Equals(authorId));
var bestSellerBook = existingAuthor.Books.FirstOrDefault(x=> x.Id.Equals(bookId));
existingAuthor.Name = "xxxxxxx";
bestSellerBook.Name = "xxxxxxxxxxx";
context.Authors.Attach(existingAuthor);
context.ObjectStateManager.GetObjectStateEntry(existingAuthor).SetModifiedProperty("Name");
context.SaveChanges();
有什么建议吗?
How do you set up SetModifiedProperty for a nested property?, in other words, I have an entity author whose entity have a books collection, I need change just a book name.
var existingAuthor = authors.FirstOrDefault(x => x.Id.Equals(authorId));
var bestSellerBook = existingAuthor.Books.FirstOrDefault(x=> x.Id.Equals(bookId));
existingAuthor.Name = "xxxxxxx";
bestSellerBook.Name = "xxxxxxxxxxx";
context.Authors.Attach(existingAuthor);
context.ObjectStateManager.GetObjectStateEntry(existingAuthor).SetModifiedProperty("Name");
context.SaveChanges();
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须获取持有已更改属性的实体的对象状态条目=在您的情况下它必须是书:
You must get object state entry for the entity holding the property which has changed = in your case it must be the book: