更新不先查询记录? [英] Update a record without first querying?
本文介绍了更新不先查询记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以说,我查询数据库并加载项的列表。然后我打开详细视图形式的项目之一,而不是重新查询该项目从数据库中,我从列表数据源创建该项目的一个实例。
Lets say I query the database and load a list of items. Then I open one of the items in a detail view form, and instead of re-querying the item out of the database, I create an instance of the item from the datasource in the list.
有没有办法运行,免去了单个项目的纪录,我可以更新数据库记录?
Is there a way I can update the database record without fetching the record of the individual item?
下面是一个示例如何我现在做的:
Here is a sample how I am doing it now:
dataItem itemToUpdate = (from t in dataEntity.items
where t.id == id
select t).FirstOrDefault();
然后拉动记录后我更新的项目的一些价值观和推回录:
Then after pulling the record I update some values in the item and push the record back:
itemToUpdate.itemstatus = newStatus;
dataEntity.SaveChanges();
我想会有更好的方式来做到这一点,任何想法?
I would think there would be a better way to do this, any ideas?
推荐答案
您应该使用连接() 方法。
这篇关于更新不先查询记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文