Linq to Sql 合并数据
2016-03-18 15:09
351 查看
一张表的Insert,Upadate,Delete 如何用Linq To Sql 简洁的完成
两种方法
1.使用临时表,先将数据插入到临时表中,再Merge到源表
An ORM is the wrong tool for performing batch operations, and Linq-to-SQL is no exception. In this case I think you have picked the right solution: Store all entries in a temporary table quickly, then do the UPSERT using merge.
The fastest way to store the data to the temporary table is to use SqlBulkCopy to
store all data to a table of your choice.
2.代码如下
两种方法
1.使用临时表,先将数据插入到临时表中,再Merge到源表
An ORM is the wrong tool for performing batch operations, and Linq-to-SQL is no exception. In this case I think you have picked the right solution: Store all entries in a temporary table quickly, then do the UPSERT using merge.
The fastest way to store the data to the temporary table is to use SqlBulkCopy to
store all data to a table of your choice.
2.代码如下
foreach (var line in linesFromService) { var kill = db.Kills.FirstOrDefault(t=>t.ToonId==line.ToonId && t.BossId==line.BossId); if (kill == null) { kill = new Kills() { ToonId = line.ToonId, BossId = line.BossId }; db.Kills.InsertOnSubmit(kill); } kill.LastKillTime = line.LastKillTime; } db.SubmitChanges();
问答链接:http://stackoverflow.com/questions/3188075/do-merge-using-linq-to-sql
相关文章推荐
- SQLServer中merge函数用法详解
- SQL中Merge用法详解
- Android中使用include标签和merge标签重复使用布局
- Oracle中merge into的使用
- Oracle中merge into的使用
- oracle merge into用法
- oracle中merge的用法
- svn-merge命令摘录
- postgres 模拟merge 插入或者对已存在进行更新
- 数字转化为人民币大写
- 使用svn merge实现回退版本
- 各种排序算法java实现,好文,做个备份
- git 小型团队项目git管理
- aaaaaaaaaaaaaaa
- 排序算法总结
- 打包msde
- 使用svn开发,目录的约定与开发流程
- 全排列算法的递归与非递归实现
- Insertion Sort and Merge Sort
- 【学习总结】merge的用法