问题描述
我正在尝试使用SQL Server Compact实体框架。我可以执行以下读取: var context = new TestEntities();
foreach(var p in context.Personnes)
{
Console.WriteLine(p.prenom ++ p.nom);
}
但我无法执行insert:
var context = new TestEntities();
context.Personnes.AddObject(new Personne(){nom =Test,prenom =Test});
context.SaveChanges();
当我尝试使用 UpdateException
做这个。 Personne
表只有3列: id(int,primary key),nom(varchar)和prenom(varchar)。
以下是运行程序时的显示:
感谢你:)
SqlServer Compact不支持服务器端密钥生成。您必须在应用程序侧生成密钥。所以设定 id
。这是一个例子。
context.Personnes.AddObject(new Personne(){id = lastId ++,nom =Test,prenom =Test});
您必须维护 lastId
。我上面写的代码只能在单线程中使用。
I am trying to use Entity Framework with SQL Server Compact. I can perform reading such as :
var context = new TestEntities();
foreach (var p in context.Personnes)
{
Console.WriteLine(p.prenom + " " + p.nom);
}
but I can't perform insert :
var context = new TestEntities();
context.Personnes.AddObject(new Personne() {nom = "Test", prenom = "Test" });
context.SaveChanges();
An UpdateException
is raised when I try to do this. The Personne
table has just 3 columns: id (int, primary key), nom (varchar) and prenom (varchar).
Here is the display I have when I run the program :
Thank you :)
SqlServer Compact doesn't support server-side key generation. You must generate key on application side. So set id
explicitly. Here is example.
context.Personnes.AddObject(new Personne() {id = lastId++, nom = "Test", prenom = "Test" });
You have to maintain lastId
. Code that I wrote above will work only in single thread.
这篇关于使用实体框架SQL Server Compact时的UpdateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!