This is a migrated thread and some comments may be shown as answers.

cannot insert after UpdateSchema()

1 Answer 35 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chom
Top achievements
Rank 1
Chom asked on 29 Aug 2013, 06:31 PM
I have built a fluent context model using code only and I can create table no problem after calling the context.UpdateSchema().

However when I try to insert some data into a table after I call UpdateSchema() the data does not get inserted in tot he table.

public static void InsertManufacturerInfo(string ProjectFilePath, string ProjectName)

{

using (ProjectSqlCeFluentContext db = new ProjectSqlCeFluentContext(ProjectFilePath, ProjectName))

{

//Create and/or update schema before adding any data....

db.UpdateSchema();

Platform p = new Platform

{

Manufacturer = "some name here",

PlatformType = "my platform"

}

db.Add(p);

db.SaveChanges();

}

}

Does anybody know what the problem is?

Help much appreciated.

Thanks

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 30 Aug 2013, 11:50 AM
Hi Chom,

Generally, the described behaviour is caused by a peculiarity in the process of persisting data to the database file in SQL Server Compact Edition. The posted method indeed creates/updates the schema and SaveChanges() commits the new record in memory but if the process is terminated before the disposal of the context (and the connection used in the transaction), the physical file is not updated.

A solution is to set the Flush Interval property of the connection string to 1. That way data will be written to the database file after the call to SaveChanges().

Please kindly find additional details about your scenario in the corresponding support thread.

If you experience other issues or have questions, do not hesitate to get back to us.


Regards,
Doroteya
Telerik
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Tags
Getting Started
Asked by
Chom
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or