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
  • 相关阅读:
    【转帖】电阻电容的封装
    FT2232H的MCU Host Bus Emulation 模式
    google cpp style guide
    CY7C131 BUSY信号线的接法
    有关沟通的常识
    关于for和foreach,兼顾效率与安全
    绩效面谈中处理分歧的小窍门
    SQL 合并列值和拆分列值
    如何保护.net中的dll文件(防止破解、反编译dll)(转)
    .NET框架图解之五:System.Reflection
  • 原文地址:https://www.cnblogs.com/lipf/p/2357096.html
Copyright © 2011-2022 走看看