Skip to content

Commit 916fa5c

Browse files
committed
Refactoring
1 parent d9047e6 commit 916fa5c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

SQLite.CodeFirst/Builder/ColumnCollectionBuilder.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,28 @@ private IEnumerable<ColumnStatement> CreateColumnStatements()
3939
}
4040
};
4141

42-
if (!property.Nullable && property.StoreGeneratedPattern != StoreGeneratedPattern.Identity) // Only mark it as NotNull if it should not be generated.
43-
columnStatement.ColumnConstraints.ColumnConstraints.Add(new NotNullConstraint());
44-
45-
if (property.StoreGeneratedPattern == StoreGeneratedPattern.Identity)
46-
{
47-
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-
}
42+
AddNullConstraintIfNecessary(property, columnStatement);
43+
AddPrimaryKeyIfNecessary(property, columnStatement);
5144

5245
yield return columnStatement;
5346
}
5447
}
48+
49+
private static void AddPrimaryKeyIfNecessary(EdmProperty property, ColumnStatement columnStatement)
50+
{
51+
if (property.StoreGeneratedPattern == StoreGeneratedPattern.Identity)
52+
{
53+
columnStatement.ColumnConstraints.ColumnConstraints.Add(new PrimaryKeyConstraint());
54+
// Must be INTEGER else SQLite will not generate the Ids
55+
columnStatement.TypeName = columnStatement.TypeName.ToLower() == "int" ? "INTEGER" : columnStatement.TypeName;
56+
}
57+
}
58+
59+
private static void AddNullConstraintIfNecessary(EdmProperty property, ColumnStatement columnStatement)
60+
{
61+
if (!property.Nullable && property.StoreGeneratedPattern != StoreGeneratedPattern.Identity)
62+
// Only mark it as NotNull if it should not be generated.
63+
columnStatement.ColumnConstraints.ColumnConstraints.Add(new NotNullConstraint());
64+
}
5565
}
5666
}

0 commit comments

Comments
 (0)