C# Entity Framework Basics Extending Our Entity Data Model Defining a Foreign Key Property

Dávid Molnár
Dávid Molnár
26,896 Points

Entity Framework: How to give Id values uint type?

Just started learning Entity Framework and as I see all my Id values must be defined as int otherwise it's not working as intended. Might I change somehow the "required" int type to a larger or unsigned type?

1 Answer

Steven Parker
Steven Parker
171,092 Points

Why would you want to change the ID type? Using "int" should be appropriate for ID's no matter what other data is carried in the record.

Dávid Molnár
Dávid Molnár
26,896 Points

I just had the idea: "Why would I have a type that can be negative for Id, can I change that?"

Steven Parker
Steven Parker
171,092 Points

Typically, you want the type to match what is used in the database, and "int" is most likely to be it. Also, the sign is unimportant, ID's only have to be unique, they aren't compared by magnitude. And whether or not they are allowed, negative values are not likely to be assigned as a record ID.