如何只更新MVC5中的一列表? [英] How to update just a single column of table in MVC5 ?

查看:62
本文介绍了如何只更新MVC5中的一列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的服务:

This is my service:

public string CloseDay(string date)
        {
            string Message = string.Empty;
            try
            {
                Session session = new Session();
                session.Status = "C";
                //db.Update<Session>(session.Status, a => a.SessionDate == Convert.ToDateTime(date));
                db.Update<Session>(session, a => a.SessionDate == Convert.ToDateTime(date));
                Message = "Day Closed Successfully";
            }
            catch (Exception Ex){ Message = Ex.Message; }
            return Message;
        }





我的代码正在运行,但问题是,它会更新整行。我希望它只更新一列。正如您在评论中看到的那样,我尝试只传递一列。但这会引发错误。请帮助..



My code is working but the problem is, it updates the whole row. I want it to update just one column. I tried passing just one column as you can see in the comment. But that throws an error.Please help..

推荐答案

使用修补程序进行patial更新,使用 AddRange 进行插入多行。
Use Patch for patial update and AddRange for inserting multiple rows.


这篇关于如何只更新MVC5中的一列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆