重新添加实体框架项而无需克隆 [英] ReAdd Entity Framework items without clonning

查看:227
本文介绍了重新添加实体框架项而无需克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在C#中有一个Entity Framework数据库.为了提高工作效率,我需要将Tables转换为List<RowClass>,然后使用列表.当我想将列表保存到表中时,我必须删除所有行,然后将列表项读到表中.问题在于,Entity Framework不允许您添加先前删除的项目.我必须克隆项目.实体克隆似乎很困难.有什么方法可以改变实体项目,使其看起来像是实体框架的不同对象吗?

Hi,
I have an Entity Framework database in C#. For working efficient, I need to convert Tables to List<RowClass> then work with the list. When I want to save the list to the table, I have to delete all rows then readd list items to the Table. The problem is that Entity Framework does not let you add an item which is deleted previously. I have to clone the Items. Entity cloning seems to be difficult. Is there any way to change an entity item in a way that looks as a different object for entity framework?

Mark Nischalke写道:
Mark Nischalke wrote:

我建议您阅读有关Entity Framework及其使用方法的更多信息.

I suggest you read more about Entity Framework and how to use it.


谢谢你的建议.大多数网站都是无用的.您知道EF的任何全面参考吗?


Thanks for your advice. Most of websites are useless. Do you know any comprehensive reference for EF?

推荐答案

使用EF,您不能使用表,而可以使用实体.如果要添加先前检索到的实体,则必须将其附加到上下文.

我建议您阅读有关实体框架及其使用方法的更多信息.
With EF you don''t work with tables, you work with entities. If you want to add an entity that was retrieved previously you must attached it to a context.

I suggest you read more about Entity Framework and how to use it.


这篇关于重新添加实体框架项而无需克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆