Entity Framework auto incrementing field, that isn't the Id

前端 未结 3 932
温柔的废话
温柔的废话 2020-12-05 13:19

I know this isn\'t the most ideal solution, but I need to add an auto incrementing field to one of my EF Code First objects. This column id NOT the Id, which is a guid.

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 13:21

    For those stumbling onto this question for EF Core, you can now create an auto-incrementing column with your model builder as follows:

    builder.Entity().Property(e => e.YourAutoIncrementProperty).UseNpgsqlIdentityAlwaysColumn();
    

    Reference: https://www.npgsql.org/efcore/modeling/generated-properties.html

提交回复
热议问题