在WCF中使用LINQ to SQL我有一個更新記錄方法,我手動分配每個更新的屬性。例如,您可以使用LINQ to SQL實體更新數據庫嗎?
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();
}
}
這是LINQ to SQL中,或LINQ到實體? –
這是Linq到SQL – Anthbs