How to choose GUID as the primary key in SQL compact?

85 Views Asked by At

Hi I create C# windows form project and use "Microsoft® SQL Server® Compact 4.0 SP1" as database. I create my project with entity framework and code first approach. but I get some error. I want use GUID as type of primary key for tables and my code is:

   [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public Guid id { get; set; }

but I get this error:

InvalidOperationException: Server-generated keys are only supported for identity columns. The column 'id' has type 'SqlServerCe.uniqueidentifier', which is not a valid type for an identity column.

and when remove [DatabaseGenerated] and [key] I get duplicate error. I searching and find SQL Compact in entity framework only knows int and big int as primary key and auto increment it, but I am not sure. how can i fix this and use GUID and primary key? pleases help.

0

There are 0 best solutions below