[英]c# linq to sql - updating database table
I'm wondering is this a bad concept of usage linq to sql to update item in my database, what I am doing is: I'm changing status of my selected item (talking about orders) from 0 to 1 and it looks like this (current code): 我想知道这是使用linq到sql来更新数据库中项目的错误概念,我正在做的是:我正在将所选项目的状态(谈论订单)从0更改为1,看起来像这样(当前代码):
Method I'm calling to set/change my item status: 我正在调用的方法来设置/更改我的商品状态:
OrdersController.SetOrderStatusTrue(orderNumber);
Method's code: 方法的代码:
public static void SetOrderStatusTrue(int numberOforder)
{
DataServices.DB.procedure_SetOrderStatus_ToTrue(numberOforder); //procedure which will set status to "1".
DataServices.DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,DataServices.DB.Orders.Where(nmbr => nmbr.OrderNumber == numberOforder)); //is this a bad concept to call refresh ?
}
So I'm wondering is this bad concept to call Refresh
Method every time I'm changing my item status, Maybe I should somehow apply SubmitChanges
method, could anyone tell me which concept is better, this concept also work, but I read on few posts that is not good practice to call refresh like this every time, so is that true and how should it look with SubmitChanges
method? 所以我想知道每次更改项目状态时都调用
Refresh
Method这个不好的概念,也许我应该以某种方式应用SubmitChanges
方法,谁能告诉我哪个概念更好,这个概念也可以,但是我读了几本并非每次都这样调用refresh的好方法,那么这是正确的,使用SubmitChanges
方法应该如何看待?
Cheers 干杯
Maybe take a look at this post: Linq to sql submit changes () or .Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, "entity to update") 也许看看这篇文章: Linq到sql提交更改()或.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,“更新实体”)
Basically whats being said there is : Refresh is pretty much never needed because normally you are making all writes through entities. 基本上说的是:几乎不需要刷新,因为通常您是通过实体进行所有写入的。 This means that the entities are always up to date.
这意味着实体始终是最新的。
Hopefully this anwers your question. 希望这能回答您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.