如何更新/修改 LINQ EntitySet?
在我的 LINQ to SQL 生成的类中,我有一些包含 EntitySet 的类。
一切看起来都很棒,直到我需要修改 EntitySet(添加、删除一些关系)。 我认为这样做会起作用:
User.Actions = newUserActions; //This is how I used it with NHibernate
然后,当我尝试提交更改时,我可能会收到重复的键异常,这意味着在分配新操作之前不会清除旧操作,并且其中一些操作可能会重复;我必须手动完成吗?
执行此操作的最佳方法是什么(更新实体集)?建议?
谢谢
In my LINQ to SQL generated classes I have some classes containing EntitySets.
Everything looks great until I need to modify the EntitySet (add, delete some relationships).
I thought that it was going to work doing something like:
User.Actions = newUserActions; //This is how I used it with NHibernate
Then when I try to submit changes, I may get a duplicate key exception, that means it is not clearing the old actions before assigning the new ones and some of them may be repeated; do I have to do it manually ?
What is the best way to do this (update the EntitySet) ? Suggestions?
Thnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来我必须手动完成。我的意思是首先删除关系(EntitySet):
然后分配“新”EntitySet:
我做到了这一点,但是......
我必须对数据库应用 2 SubmitChanges() 吗?
难道不是更好的方法吗?
It appears that I have to do it manually. I mean first delete the relationships (EntitySet):
And after that, assign the "new" EntitySet:
I made it work doing that but...
DO I have to apply 2 SubmitChanges() to database?
Isn't it a better way to do it?
这不是更容易吗?
Wouldn't this be easier?
SQL数据库关系中是否设置了级联删除?您需要这个集合和重新生成的类来解决这个问题。
In the SQL database relationships did you have cascade delete set? You need this set and the classes regenerating to resolve this.