locked
How to create IsIdentity field using Entity framework RRS feed

  • Question

  • User-1499457942 posted

    Hi

       How to create IsIdentity field using Entity framework

    Thanks

    Wednesday, January 18, 2017 12:50 PM

All replies

  • User753101303 posted

    Hi,

    By convention if a property is named "Id" or using the class name followed by id (case insensitive) it is considered as an identity column. You can also use data annotations or the fluent API (or even maybe custom conventions) to designate which property will generate an identity column (Key or HasKey).

    I suggest to have a look at https://msdn.microsoft.com/en-us/library/ee712907(v=vs.113).aspx (here "Conventions", "Data annotations" and "Fluent API" chapters) which is quite a good summary of most if not all EF features...

    Wednesday, January 18, 2017 1:48 PM
  • User-1499457942 posted

    Hi

      I have done like below but it showing IsIdentity = 'No'

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

    Thanks

    Wednesday, January 18, 2017 2:16 PM
  • User197322208 posted

    JagjitSingh

    but it showing IsIdentity = 'No'

    Does it show in the database? How was the database generated?

    I have not read with attention . The GUID are not identity . See AngelinaJolie (;-) )answer 

    Wednesday, January 18, 2017 2:30 PM
  • User-1499457942 posted

    Hi

       Yes that is the problem . How it can be done . I am trying through EF5. 

    Thanks

    Wednesday, January 18, 2017 3:47 PM
  • User-832373396 posted

    Hi JagjitSingh,

    I have done like below but it showing IsIdentity = 'No'

    It simply means the column uses the Identity(seed, increment) function to provide values for a primary key (usually).

    But because Guid is irregular,it can't  set seed value, so we can't not set identity ,And I can't manually set it  too  :

    Note: This column created via Code First:

    Best regards,

    Jolie

    Monday, January 23, 2017 11:07 AM