Reputation:
i would like to update an existing item in a sql database using linq.
i have tried with this.
public void UpdateFoodDrinkTobacco(int id, string preservationTechniqueCodes, bool isHomogenised)
{
var item = (from item in _db.FoodDrinkAndTobacco
where item.id equals id
select item.isHomogenised);
item = isHomogenised;
_db.SubmitChanges();
}
but this is not working for me.
Hope some of you have a suggestion on how to do this.
Upvotes: 1
Views: 89
Reputation: 628
You could do somthing like this.
public void UpdateFoodDrinkTobacco(int id, string preservationTechniqueCodes, bool isHomogenised)
{
var item = _db.FoodDrinkTobaccos.Where(i => i.id == id).Select(i => i);
if (item == null) return;
item.preservationTechniqueCodes = preservationTechniqueCodes;
item.isHomogenised = isHomogenised;
_db.SubmitChanges();
}
like this you can change all of the parameters. And i think i looks a little better when you use lambda expressions instead of the other way you did it. Hope this works.
Upvotes: 1