2013-08-28 61 views
0

堆垛機,WCF ado.net插入記錄(最後)

我一直困擾這個問題很長時間,我終於決定在這裏發佈我的問題。

這是什麼困擾我。我正在爲windowsphone 8編寫一個應用程序。這個應用程序圍繞本地和遠程數據庫進行。本地數據庫部分是容易的部分。但是現在,我想使用我的WCF服務將記錄插入到遠程數據庫(在服務器端使用帶有服務的ADO.NET)。我已經成功地在遠程數據庫中插入記錄,但有一個問題(至少針對我的目標)。我的數據庫表(其中im插入)有一個主鍵,我不想告訴/插入這個主鍵時,我插入數據到數據庫中。我只想在最後一條記錄後插入我的新記錄。有沒有辦法做到這一點?

這是我到目前爲止有:

private MeasurementEntities Context; 
Context = new MeasurementEntities(new Uri("http://192.168.11.240:85/NFCDataService.svc/")); 

public void SaveAnwsersToDbLocal(bool ans1, bool ans2, bool ans3) 
     { 
      Measurement temp = new Measurement(); 

      temp.Anwser1 = ans1; 
      temp.Anwser2 = ans2; 
      temp.Anwser3 = ans3; 
      temp.MeasurementId = 1; // this is the primary key, and want to get rid of this. 
      // i want to insert at end of database. but how? 

      // add to local collection. 
      _MeasurementCollection.Add(temp); 

      Context.AddToMeasurements(temp); 

      Context.BeginSaveChanges(SaveChangesCallback, temp); 

      //if wifi is on: 
      UploadMeasurements(); 
     } 

回答

0

好了,這是非常愚蠢的。在我的mssql表中,我沒有啓用該功能來添加具有自動增量的行。至少,我已啓用它,但增量設置爲0.因此它會指向相同的記錄。