zoukankan      html  css  js  c++  java
  • C#Linq To Entry

    public void updateUser(Server.Data.User User, out string resMsg)
            {           
                try
                {               
                    var tempF = db.User.First(f => f.Id == User.Id);
                    var tempFT = db.UserType.First(ft => ft.Id == User.UserTypeId);
                    if (tempF!=null)
                    {
                        if (tempFT != null)
                        {
                            tempF.CreatorId = User.CreatorId;
                            tempF.UserName = User.UserName;
                            tempF.UserSize = User.UserSize;
                            tempF.UserType = tempFT;
                            tempF.LatestVersion = User.LatestVersion;
                            tempF.ModifierId = User.ModifierId;
                            tempF.ModifyDate = DateTime.Now.ToString();
                            db.SaveChanges();
                            resMsg = "Update User success";
                        }
                        else
                        {
                            resMsg = "Update User failure:UserType not found";
                        }
                    }
                    else
                    {
                        resMsg = "Update User failure:User not found";
                    }
                }
                catch (Exception ex)
                {
                    resMsg = "Update User failure\n" + ex.ToString();
                }
            }
    注意外键约束,如果主键ID为自增长,注意将表的 IDentity 设为 on
  • 相关阅读:
    rails s 命令不起作用
    ubuntu下virtualbox共享usb
    ubuntu15.04 无法识别exfat格式
    .net core 2.2 修改IdentityUser主键标识类型
    Mac os 安装node.js及环境变量的配置过程
    常见互联网网络名词整理
    assert的用法
    Mac系统中 改变 pip总是默认安装在Mac上自带的python上为python3
    测试工程师的发展之路
    MySQL的mysql-8.0.17-winx64版本安装过程中遇到的问题
  • 原文地址:https://www.cnblogs.com/lipf/p/2357096.html
Copyright © 2011-2022 走看看