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
  • 相关阅读:
    Axure Base 10 动态面板滑动效果
    算法分析----第一节
    使用切片拦截Rest服务
    Java中Memcache的使用
    activitemq与spring的整合
    Android的Fragment中的互相通信-桥梁activity
    Android模拟微信主页面的Demo
    Android动态添加Fragment
    Android的Fragment的第一种声明方式
    Android使用内容提供者实现增删改查操作
  • 原文地址:https://www.cnblogs.com/lipf/p/2357096.html
Copyright © 2011-2022 走看看