Skip to content

Commit 5176827

Browse files
committed
Added support for autoincremented PrimaryKey
1 parent 0e7b9e7 commit 5176827

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

SQLiteEfCodeFirstDbCreator/Builder/ColumnCollectionBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ private IEnumerable<ColumnStatement> CreateColumnStatements()
3939
}
4040
};
4141

42-
if (!property.Nullable)
42+
if (!property.Nullable && property.StoreGeneratedPattern != StoreGeneratedPattern.Identity) // Only mark it as NotNull if it should not be generated.
4343
columnStatement.ColumnConstraints.ColumnConstraints.Add(new NotNullConstraint());
4444

45-
if(property.StoreGeneratedPattern == StoreGeneratedPattern.Identity)
45+
if (property.StoreGeneratedPattern == StoreGeneratedPattern.Identity)
46+
{
4647
columnStatement.ColumnConstraints.ColumnConstraints.Add(new PrimaryKeyConstraint());
48+
// Must be INTEGER else SQLite will not generate the Ids
49+
columnStatement.TypeName = columnStatement.TypeName.ToLower() == "int" ? "INTEGER" : columnStatement.TypeName;
50+
}
4751

4852
yield return columnStatement;
4953
}

0 commit comments

Comments
 (0)