How to generate and auto increment Id with Entity Framework

后端 未结 2 1101
遇见更好的自我
遇见更好的自我 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.

    0 讨论(0)
  • 2020-11-29 07:49

    This is a guess :)

    Is it because the ID is a string? What happens if you change it to int?

    I mean:

     public int Id { get; set; }
    
    0 讨论(0)
提交回复
热议问题