简体   繁体   中英

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):

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?

Cheers

Maybe take a look at this post: Linq to sql submit changes () or .Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, "entity to update")

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM