人々のグループをデータベース テーブルに挿入しようとしています。問題なくデータベースから選択できますが、入力しようとすると
Cannot add an entity with a key that is already in use
私はこれが何を意味するのか知っていますが、なぜそれが起こっているのですか?テーブルIDを増やしました。これが私のコードです。
public static List<Person> GetPeople(DataContext db)
{
List<Person> people = new List<Person>();
Table<Person> People = db.GetTable<Person>();
for (int i = 0; i < 5; i++)
{
Person pers = new Person();
pers.PersFirstName = "Wesley " + i;
//pers.PersId is the primary key that I want to auto-increment and not have to set it here
people.Add(pers);
}
People.InsertAllOnSubmit(people);
People.Context.SubmitChanges();
IQueryable<Person> query =
from person in People
select person;
return people;
}
問題はラインで発生します
People.InsertAllOnSubmit(people);
Linq で自動インクリメントを設定する特別な方法はありますか?