Insert Records into Sqlite DB using ADO.NET Entity Framework?
I'm tring to insert some records into my Sqlite database using the Entity Framework. I do not have a problem connecting to the database or mapping to the database. At least, I don't think I do. When I call "SaveChanges" an exception is fired that states:
Unable to update the EntitySet 'RawReadings' because it has a DefiningQuery and no element exists in the element to support the current operation.
Here is my code:
PyEntities p = new PyEntities();
System.Data.Objects.ObjectQuery<RawReading> readings = p.RawReadingSet;
RawReading rr = new RawReading();
rr.DateTime = new DateTime();
rr.Group = "353";
rr.Value = 555.33f;
p.AddObject("RawReadingSet", rr);
//EntityKey key = p.CreateEntityKey("RawReadingSet", rr);
try {
p.SaveChanges(false);
}
catch (Exception ex) {
MessageBox.Show(ex.InnerException.InnerException.Message);
}
What am I doing wrong? Has anyone else had this problem?
Thanks in advance.
看起来问题是由于我的Sqlite数据库没有定义主键而导致的。
链接地址: http://www.djcxy.com/p/64918.html