I can read from SQL server database but can not save
I am using Entity Framework. I can read the data from SQL server 2008 but can not save the data. Here is my connection string. I manually ran the Insert statement on the database. It works. But I can't insert from the code.
<add name="TestEntities" connectionString="metadata=res://*/Models.TestDB.csdl|res://*/Models.TestDB.ssdl|res://*/Models.TestDB.msl;provider=System.Data.SqlClient;prov开发者_开发问答ider connection string="Data Source=TESTDEV;Initial Catalog=AttachDbFilenameC:\test\TestDB.mdf;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
using (TestEntities db1 = new TestEntities())
{
Order O = new Order();
O.OrderTypeID = 1;
O.UserID = 29210;
db1.AddToOrderss(O);
db1.SaveChanges();
}
I deleted the existing model and created a new database and new model. It's working fine. Thanks for the hint James.
精彩评论