在 WCF 中使用 LINQ to SQL 我有一个更新记录方法,ATM 我手动分配每个更新的属性。例如。
public void UpdateMachineRecord(Guid SessionID, int MachineRecordID, MachineRecord machineRecord)
{
if (!ValidSession(SessionID))
return;
using (MMHLINQSQLDataContext database = new MMHLINQSQLDataContext())
{
MachineRecord record = database.MachineRecords.Single(mr => mr.Job.OperationID == MachineRecordID);
record.ChangedBy = UserSession(SessionID).Name;
record.ChangedDate = DateTime.Now.ToString();
record.Date = machineRecord.Date;
record.EDI = machineRecord.EDI;
...
database.SubmitChanges();
}
}
我的问题是:有没有办法使用整个实体更新记录?
例如。
public void UpdateMachineRecord(Guid SessionID, int MachineRecordID, MachineRecord machineRecord)
{
if (!ValidSession(SessionID))
return;
using (MMHLINQSQLDataContext database = new MMHLINQSQLDataContext())
{
MachineRecord record = database.MachineRecords.Single(mr => mr.Job.OperationID == MachineRecordID);
record = machineRecord;
database.SubmitChanges();
}
}