Linq中更新操作的思路

我们更新的时候可以写一个更新的方法

public void ModifyTeacher(String num,String name.int age...........................)

可以传很多参数。

 

不过这样可读性比较差。我们可以这样:

        /// <summary>
        /// 修改教师信息
        /// </summary>
        /// <param name="newTeacher"></param>
        public void ModifyTeacher(M_Teacher newTeacher)
        {
            try
            {
                M_Teacher oldTeacher = ReadModel(newTeacher.Num);
                oldTeacher.Name = newTeacher.Name;
                oldTeacher.Gender = newTeacher.Gender;
                oldTeacher.Type = newTeacher.Type;
                oldTeacher.CollegeNum = newTeacher.CollegeNum;
                oldTeacher.Birth = newTeacher.Birth;
                oldTeacher.idcard = newTeacher.idcard;
                oldTeacher.rollyear = newTeacher.rollyear;
                dc.SubmitChanges();
            }
            catch
            { }
        }

 

当然,我们可以把更新每一个字段都写一个方法。

上一篇:解决 Callout位置不更新的问题


下一篇:打造“零距离”互动直播间,低延时流媒体技术实践