Skip to content

Non-nullable (int) type not allowed as Primary key #65

@gabh

Description

@gabh

I have read the wiki and it says-"[PrimaryKey] - mark the property used as the primary key, which must be an int?, long?, or GUID? with this attribute."

Does it mean "int" (non-nullable int) is not allowed as Primary key?

When I run my code (that uses SimpleSave nuget package) and with non-nullable int as primary key, I do get an exception which says that int as primary key is not allowed.

Looked around further in wiki for more information as to why "int" would not be allowed as primary key, I did not find anything. Not satisfied, I ventured into the source code and I found conflicting checks for primary key type in a couple of files (first one does not allow int, while the second one does):

\Dapper.SimpleSave-master\src\Dapper.SimpleSave\Impl\ DtoMetadataValidator.cs
image

\Dapper.SimpleSave-master\src\Dapper.SimpleSave\Impl\ ScriptBuilder.cs
image

Moreover, when I change the check in my local copy of SimpleSave source code to allow "non-nullable int", and run my model (with non-nullable int as primary key) against it, I am able to save my model into database fine.

So, is non-nullable int really not allowed as Primary key, or is it just a bug that needs fixed?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions