locked
MVC5 Entity Framework code first approach RRS feed

  • Question

  • User-1211464864 posted

    Hi All,

    How can i create uniqueidentifier column in  Mvc  Entity framework   code code first   approach

    Thursday, August 13, 2015 9:50 AM

Answers

  • User37182867 posted

    if you just want an auto incremented integer style primary key for your table you can just use the convention of having a property with the name "Id" and it will do the rest of the work for you. If by uniqueidentifier you mean a column with type equal uniqueidentifier or GUID then just define the property type as GUID. You can define a primary key on any field by as suggested above with the "KEY" attribute as well.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 13, 2015 3:10 PM

All replies

  • User2024324573 posted

    Put [Key] attribute before the column definition, it will need the namespace System.ComponentModel.DataAnnotations

    Hope this will help

    Thursday, August 13, 2015 3:04 PM
  • User37182867 posted

    if you just want an auto incremented integer style primary key for your table you can just use the convention of having a property with the name "Id" and it will do the rest of the work for you. If by uniqueidentifier you mean a column with type equal uniqueidentifier or GUID then just define the property type as GUID. You can define a primary key on any field by as suggested above with the "KEY" attribute as well.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 13, 2015 3:10 PM
  • User2053451246 posted

    How can i create uniqueidentifier column in  Mvc  Entity framework   code code first   approach

    public Guid MyUniqueidentifier { get; set; }

    Thursday, August 13, 2015 3:46 PM