堆垛工,
我为这个问题困扰了很长时间,所以我终于决定在这里提出我的问题。
这就是困扰我的事。我正在为windowsphone 8编写一个应用程序,这个应用程序围绕一个本地和一个远程数据库。本地数据库部分是容易的部分。但是现在,我想使用我的WCF服务将记录插入到我的远程db中(在服务器端使用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();
}
发布于 2013-09-03 11:09:58
好吧,这真是太蠢了。在我的mssql表中,我没有启用该特性来添加带有自动增量的行。至少,我启用了它,但是增量被设置为0。所以它会指向同样的记录。
https://stackoverflow.com/questions/18483510
复制相似问题