How to generate and auto increment Id with Entity Framework

后端 未结 2 1125
遇见更好的自我
遇见更好的自我 2020-11-29 07:30

Revised entire post.

I\'m trying to post the following JSON POST request via Fiddler:

{Username:\"Bob\", FirstName:\"Foo\", LastName         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 07:40

    You have a bad table design. You can't autoincrement a string, that doesn't make any sense. You have basically two options:

    1.) change type of ID to int instead of string
    2.) not recommended!!! - handle autoincrement by yourself. You first need to get the latest value from the database, parse it to the integer, increment it and attach it to the entity as a string again. VERY BAD idea

    First option requires to change every table that has a reference to this table, BUT it's worth it.

提交回复
热议问题