2

I heard that this issue is fixed in SQL Server Compact Edition 4.0 CTP

As recently I just stepped into SQL Server CE and Entity Framework, and VS2010 not yet supporting SQL Server CE 4.0

I think I would need a work around for this issue

Can I know how to generate an Integer type Identity Primary Key inside the constructor of the Entity Object

   public partial class Book 
 {

  public Book()
  {
   // SQL Server Compact does not support entities with server-generated keys or values when it is used 
   // with the Entity Framework. Therefore, we need to create the keys ourselves.


   Id = // Generating a Integer Identity Id here
     //similar to Guid.NewGuid();

  }
}

Your help is much appreciated.

bobs
  • 21,844
  • 12
  • 67
  • 78
AlexvsCode
  • 21
  • 2

3 Answers3

1

I've used VS2010 and SQL Server CE with Entity Framework CTP4 Code-First and it worked with no problems. I've installed both thing using NuPack (now NuGet - http://nuget.codeplex.com/) and used it with ASP.NET MVC 3 Beta application.

The latest version of SQLCE on NuGet is 4.0.8435.1 and to use it with EF you have SQLCE.EntityFramework 4.0.8435.1 on there.

gligoran
  • 3,267
  • 3
  • 32
  • 47
0

I met same problem, I take max value of the Id column after that add one. If you are developing a desktop application you should mind problem in the following link:Problem when inserting data into SQL Compact by ADO.Net Entity Framework

Community
  • 1
  • 1
Linh
  • 1,024
  • 2
  • 16
  • 28
0

This is exactly what I'm looking for:

// SQL Server Compact does not support entities with server-generated keys or values when it // with the Entity Framework. Therefore, we need to create the keys ourselves.

so we have to generate our id (int) manually instead of auto generating it from SQL Server Compact.

armnov
  • 641
  • 1
  • 7
  • 16
  • It's unclear whether this is an answer or a separate question. If it's an answer can you please clarify it? If it's a question you should post it as a separate question, not as an answer. – Bill the Lizard Jan 16 '11 at 15:23
  • Sorry, I'd like to clarify that it's an answer :) Thanks. – armnov Jan 19 '11 at 12:44