Update records using LINQ

后端 未结 8 1575
迷失自我
迷失自我 2020-12-04 17:24

I need to set a value in a table for a subset of rows. In SQL, I would do this:

UPDATE dbo.Person SET is_default = 0 WHERE person_id = 5

Is

相关标签:
8条回答
  • 2020-12-04 18:09

    This worked best.

    (from p in Context.person_account_portfolio 
     where p.person_id == personId select p).ToList()
                                            .ForEach(x => x.is_default = false);
    
    Context.SaveChanges();
    
    0 讨论(0)
  • 2020-12-04 18:18
    public ActionResult OrderDel(int id)
        {
            string a = Session["UserSession"].ToString();
            var s = (from test in ob.Order_Details where test.Email_ID_Fk == a && test.Order_ID == id select test).FirstOrDefault();
            s.Status = "Order Cancel By User";
            ob.SaveChanges();
            //foreach(var updter in s)
            //{
            //    updter.Status = "Order Cancel By User";
            //}
    
    
            return Json("Sucess", JsonRequestBehavior.AllowGet);
        } <script>
                function Cancel(id) {
                    if (confirm("Are your sure ? Want to Cancel?")) {
                        $.ajax({
    
                            type: 'POST',
                            url: '@Url.Action("OrderDel", "Home")/' + id,
                            datatype: 'JSON',
                            success: function (Result) {
                                if (Result == "Sucess")
                                {
                                    alert("Your Order has been Canceled..");
                                    window.location.reload();
                                }
                            },
                            error: function (Msgerror) {
                                alert(Msgerror.responseText);
                            }
    
    
                        })
                    }
                }
    
            </script>
    
    0 讨论(0)
提交回复
热议问题