1

I'm beginner to Entity Framework. I have VS 2010 installed. I'm able to access data from a SQL Server Compact 3.5 .sdf file, but I'm not able to write using Entity Framework.

This is the code I'm using:

db.Models.AddObject(new Model() {Name="myname"});
db.SaveChanges();

and I am not able to add any new data objects to SQL Server Compact 3.5 using Entity Framework - why is that and how to deal with it?

Suggestions and guidelines are highly appreciated

timil
  • 11
  • 2
  • Check the bin/debug folder for a copy of the database, and install the SQL Server Compact Toolbox add-in for editing/viewing data – ErikEJ Oct 06 '14 at 10:16
  • Thanks ErikEJ, I mean editing SQL Server Compact data using Entity Framework 4.0? I installed SQL Server Compact Toolbox add-in able to edit existing object data but add new object via db.Models.AddObject(new Model() {Name="myname"}); db.SaveChanges(); is still creating error. – timil Oct 06 '14 at 10:21
  • 2
    Pls update your question with the error message, you do not mention anything about errors...! – ErikEJ Oct 06 '14 at 10:42
  • @ErikEJ, InnerException: System.Data.UpdateException HResult=-2146233087 Message=An error occurred while updating the entries. See the inner exception for details. Source=System.Data.Entity StackTrace: at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at System.Data.Objects.ObjectContext.SaveChanges() – timil Oct 06 '14 at 11:49
  • "Unable to cast object of type 'System.Collections.Generic.List`1[System.Data.Metadata.Edm.EdmProperty]' to type 'System.Data.Metadata.Edm.MetadataCollection`1[System.Data.Metadata.Edm.EdmProperty]'." – timil Oct 06 '14 at 11:58
  • Is that the inner exception? – ErikEJ Oct 06 '14 at 15:34
  • @ErikEJ, Yeah this is inner exception. Now I could access existing database at SQL Server Compact 3.5 and even modify or delete it using Entity framework. There is this error on creating new object at save to SQL Server Compact 3.5 using Entity frame work. Even allocating Id manually didn't help. Could u suggest any other option to create new object and pass to database beside db.Models.AddObject(new Model() {Id= 7, Name="myname"}); db.SaveChanges(); //if I comment SaveChanges() program runs but no change in database Thanking you – timil Oct 07 '14 at 02:52
  • Thanks I shorted out the problem: http://stackoverflow.com/questions/2734424/c-sharp-4-0-ef-server-generated-keys-and-server-generated-values-are-not-suppo – timil Oct 07 '14 at 03:43
  • Ok, this issue is fixed in EF 6 – ErikEJ Oct 07 '14 at 05:37

0 Answers0