0

堆垛机,

我被这个问题困扰了很久,我终于决定在这里发布我的问题。

这是困扰我的事情。我正在为 windowsphone 8 编写一个应用程序。这个应用程序围绕一个本地和一个远程数据库。本地数据库部分是简单的部分。但是现在,我想使用我的 WCF 服务将记录插入到我的远程数据库中(使用 ADO.NET 和服务器端的服务)。我已成功在远程数据库中插入记录,但有一个问题(至少对于我的目标而言)。

我的数据库表(我在其中插入)有一个主键,当我将数据插入数据库时​​我不想告诉/插入这个主键。我只想在最后一条记录之后插入我的新记录。有没有办法做到这一点?

这是我到目前为止所拥有的:

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();
        }
4

1 回答 1

0

好吧,这真的很愚蠢。在我的 mssql 表中,我没有启用添加自动增量行的功能。至少,我启用了它,但增量设置为 0。所以它会指向相同的记录。

于 2013-09-03T11:09:58.190 回答