将列表插入表中 [英] Insert List in to a table

查看:80
本文介绍了将列表插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在List< Items>中有项目对象的列表. itemList.现在,我不想将其插入到项目表中.我做的一种技术是删除表中所有现有的项目,然后插入列表.这变得非常慢.

I have list of item objects in List<Items> itemList. Now I wan''t to insert this in to the item table. One technique i did was, I delete all the existing items in the table and then insert the list. This get very slow. How can I save only the updated items in to the table.

推荐答案

根据您的配置有很多方法,但是根据此处描述的内容,我建议您在商品中添加了 IsDirty 字段.当项目上的任何内容发生更改时,请将字段设置为true.然后,当您遍历列表时,可以检查该字段是否为true,并且仅更新这些项目.此方法要求每个项目都有一个标识字段,该项目的唯一值(通常是int或Guid).您将使用此标识符在表中找到该项目的行,然后更新该行中的信息.
There are many ways depending on your configurations, but based on what is described here, I would recommend that you add an IsDirty field to your items. Set the field to true when anything on the item changes. Then when you loop through the list you can check to see if the field is true and only update those items. This method requires that each item has an identifying field, a unique value for that item (typically an int or Guid). You would use this identifier to locate the row in the table for that item, and then update the information in that row.


这篇关于将列表插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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