Entity Framework: SDF: Server-generated keys and server-generated values are not supported by SQL Server Compact.

(My friend Peter pointed me to this so I am writing this on his behalf)

Basic setup:

A simple application, an SDF (Microsoft SQL Server Compact file) and the Entity Framework.

So I created the project, added the files, created the tables, made a model, and wrote this class:

namespace LinqToEntities
{
	class Program
	{
		static void Main(string[] args)
		{
			using (Database1Entities ctx = new Database1Entities())
			{
				Test myTest = new Test() { Value1 = "Blah", Value2 = "Blah2" };

				ctx.AddToTestSet(myTest);

				ctx.SaveChanges();
			}
		}
	}
}

And this gives me a nice error on ctx.SaveChanges();sqlserver-ce

(Big image!!!)

The problem is not the database, like the error says. But the problem is that the EF just doesn’t understand it.

Here are some ‘workaround’, I quote it because I don’t really consider them a workaround.:

  • Disable autoincrement, and manually fetch the highest id, and then insert. This could lead to corruption if you are in a multi threaded  environment.
  • Use a SqlCeCommand

But it’s a breaking issue I think, and I hope they fix it in the next version.

One thought on “Entity Framework: SDF: Server-generated keys and server-generated values are not supported by SQL Server Compact.

  1. Hi,
    Please can you send me your demo. I can’t store the data in my sqlcompact database when i do savechanges

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>