Linq to sql 两种更新

1.普通更新

 public void UpdateWorkTask_Management(ObjectModel instance)

        {

            //this.WorkTask_Managemnt.Attach(instance);

            WorkTask_Managemnt workTask = this.WorkTask_Managemnt.Single(s => s.ID == instance.ID);

            workTask.Title = instance.Title;

            workTask.Content = instance.Content;

            workTask.StartTime = instance.StartTime;

            workTask.EndTime = instance.EndTime;

            workTask.TaskStatus = instance.TaskStatus;

            workTask.Priority = instance.Priority;

            workTask.IsSchedule = instance.IsSchedule;

            workTask.ModifyTime = instance.ModifyTime;

            workTask.ScheduleID = instance.ScheduleID;

            this.SubmitChanges();

        }

 

2.ExecuteCommand方式

public int UpdateSchedule_UserInfo(Schedule_Managment instance)

        {

            object[] parameters = new object[13];

            parameters[0] = instance.ID;

            parameters[1] = instance.Title;

            parameters[2] = instance.Contents;

            parameters[3] = instance.StartDate;

            parameters[4] = instance.EndDate;

            parameters[5] = instance.IsRemind;

            parameters[6] = instance.RemindType;

            parameters[7] = instance.RemindTime;

            parameters[8] = instance.IsTask;

            parameters[9] = instance.TaskID;

            parameters[10] = instance.AllDay;

            parameters[11] = instance.Priority;

            parameters[12] = instance.ModifyTime;



            StringBuilder sb = new StringBuilder();

            sb.Append("UPDATE [Schedule_Managment] SET [Title]= {1},");

            sb.Append("[Contents]= {2},");

            sb.Append("[StartDate]= {3},");

            sb.Append("[EndDate]= {4},");

            sb.Append("[IsRemind]= {5},");

            sb.Append("[RemindType]= {6},");

            sb.Append("[RemindTime]= {7},");

            sb.Append("[IsTask]= {8},");

            sb.Append("[TaskID]= {9},");

            sb.Append("[AllDay]= {10},");

            sb.Append("[Priority]= {11},");

            sb.Append("[ModifyTime]= {12} ");

            sb.Append("where ID = {0} ");

           return ExecuteCommand(sb.ToString(), parameters);

        }

删除最爽了。。。。

 public int DeleteSchedule_UserInfo(long id)

        {

            return ExecuteCommand("delete from Schedule_Managment where ID = {0}", id);

        }

 

你可能感兴趣的:(LINQ)