entity-frameworkentity-framework-ctp5

Autogenerate primary key (Guid) Entity Framework CTP5


I have a following POCO class

public class Account
    {
        [Key,DatabaseGenerated(DatabaseGenerationOption.Identity)]
        public string AccountId { set; get; }

        public string FirstName { set; get; }

        public string LastName { set; get; }

        public string Email { set; get; }


    }

I get the following exception when the database gets created

Identity column 'AccountId' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.

Solution

  • Shouldn't you have:

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

    ?