sql-server-ce-4

SqlCeParameter return Auto ID (Primary Key)

余生长醉 提交于 2020-02-02 03:44:27
问题 I have an SQL SqlCeParameter statement for example: mySQLCommand1.CommandText = @" INSERT INTO clientSubjectiveComplaints (clientSubComplaintCreated) VALUES (@ClientSubComplaintCreated) "; Once the INSERT is successful I need the auto generated ID (INT Primary Key) returned so that I can use it in a second INSERT statement. Is this possible for SqlCe ? Please if you can provide an example. 回答1: Like this: using (var connection = new SqlCeConnection(Settings.Default.Database1ConnectionString))

Entity Framework 4.1 DatabaseGeneratedOption.Identity Performance

本秂侑毒 提交于 2020-01-11 08:01:30
问题 I currently working on a application that use Entity Framework 4.1 (code first) and SQL Server CE 4.0. One of the new things I really like from SQL Server CE 4.0 are the computed values. But I have some performance problem while importing old data into my new data store system (around 50000 entries). This is my second implementation for this. The first version used Entity Framework 4.0 and SQL Server CE 3.5. But there is a huge performance difference between these implementations. The code

How can I upgrade my Sql Server CE 3.5 sdf database to Sql Server CE 4.0?

戏子无情 提交于 2020-01-10 07:51:22
问题 I need to update my SqlCE3.5 database to 4.0. I get the following error message when I'm trying to access my 3.5 sdf/database using the new CE4.0 connection provide :- System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlServerCe.SqlCeInvalidDatabaseFormatException: The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method . Anyone know how I can do this? Obviously I need to do it

Programatically retrieve the full data directory path in VB.NET

眉间皱痕 提交于 2019-12-24 21:04:37
问题 I am working on a VB.NET / WPF application which will use SQL Compact Edition databases. The application should allow the user to save and load different versions of the database. To do this, my intention was to have a standard database name (e.g. myDatabase.sdf) which would be saved in the DataDirectory . Then the user would have an option to save a version of the current data (calling it what they want e.g. savedDatabase1.sdf) and the application would then take a copy of the database from

SQL Server Compact Edition 4 - AccessViolationException

僤鯓⒐⒋嵵緔 提交于 2019-12-22 05:52:53
问题 I'm building a .NET 4 WPF application using Entity Framework code first and SQL Server Compact 4.0. I'm trying to call DbContext.SaveChanges() on a background thread to avoid blocking the UI, but I'm occasionally getting the following exception: System.AccessViolationException occurred Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=System.Data.SqlServerCe StackTrace: at System.Data.SqlServerCe.NativeMethodsHelper.OpenStore

Inserting a row and retrieving identity of new row in SQL Server CE

别说谁变了你拦得住时间么 提交于 2019-12-21 01:30:13
问题 I'm trying to insert a row and get back the new row's identity with something like this: INSERT INTO blah....; SELECT @@IDENTITY as NewID; I'm trying to execute both statements with a single invocation of a DbCommand object in C#... it doesn't seem work or I've got something wrong. I've read that Compact Edition doesn't support executing multiple statements in a batch... but I also found this: If you want to run multiple queries simultaneously, you must include a new line character for each

Entity Framework 4.1 “Code First” SetInitializer not being called again after Database.Delete

被刻印的时光 ゝ 提交于 2019-12-19 07:29:26
问题 Trying to do some unit testing with EF 4.1 code first. I have my live db (SQL Server) and my unit test DB( Sql CE). After fighting (and losing) with EF, Sql CE 4.0 and Transaction support I decided the simplest way to run my test was to: Create Db Run Test Delete Db Rinse and repeat I have my [Setup] and [TearDown] functions: [SetUp] public void Init() { System.Data.Entity.Database.SetInitializer(new MyTestContextInitializer()); _dbContext = ContainerFactory.Container.GetInstance<IContext>();

Entity Framework 4.1 “Code First” SetInitializer not being called again after Database.Delete

删除回忆录丶 提交于 2019-12-19 07:29:07
问题 Trying to do some unit testing with EF 4.1 code first. I have my live db (SQL Server) and my unit test DB( Sql CE). After fighting (and losing) with EF, Sql CE 4.0 and Transaction support I decided the simplest way to run my test was to: Create Db Run Test Delete Db Rinse and repeat I have my [Setup] and [TearDown] functions: [SetUp] public void Init() { System.Data.Entity.Database.SetInitializer(new MyTestContextInitializer()); _dbContext = ContainerFactory.Container.GetInstance<IContext>();

Code First Migrations and initialization error

[亡魂溺海] 提交于 2019-12-18 10:35:20
问题 I'm unsure about how to use the code first migration feature. In my understanding it should create my database if it's not existing already, and update it to the latest schema according to migration files. But I'm struggling with it, because I always get a lot of errors and I'm unsure overall how to use this properly.. internal class Program { private static void Main() { EntityFrameworkProfiler.Initialize(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data

LINQ to Entities StringConvert(double)' cannot be translated to convert int to string

倖福魔咒の 提交于 2019-12-18 08:56:06
问题 Problem Need to convert int to string using EF4 + SQL CE4. The recommended option of using SqlFunctions.StringConvert(double) still gives me errors. Option 1 (original). This gives me error: public static IEnumerable<SelectListItem> xxGetCustomerList() { using (DatabaseEntities db = new DatabaseEntities()) { var list = from l in db.Customers orderby l.CompanyName select new SelectListItem { Value = l.CustomerID.ToString(), Text = l.CompanyName }; return list.ToList(); } } Option 2 (most