Skip to content

Commit e4845b4

Browse files
author
Marc Sallin
committed
#27: Use UniqueConstraint in the ColumnStatementCollectionBuilder.
1 parent 20e2f50 commit e4845b4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

SQLite.CodeFirst/Internal/Builder/ColumnStatementCollectionBuilder.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private IEnumerable<ColumnStatement> CreateColumnStatements()
3636
AddMaxLengthConstraintIfNecessary(property, columnStatement);
3737
AdjustDatatypeForAutogenerationIfNecessary(property, columnStatement);
3838
AddNullConstraintIfNecessary(property, columnStatement);
39+
AddUniqueConstraintIfNecessary(property, columnStatement);
3940

4041
yield return columnStatement;
4142
}
@@ -66,5 +67,19 @@ private static void AddNullConstraintIfNecessary(EdmProperty property, ColumnSta
6667
columnStatement.ColumnConstraints.Add(new NotNullConstraint());
6768
}
6869
}
70+
71+
private static void AddUniqueConstraintIfNecessary(EdmProperty property, ColumnStatement columnStatement)
72+
{
73+
MetadataProperty item;
74+
bool found = property.MetadataProperties.TryGetValue("http://schemas.microsoft.com/ado/2013/11/edm/customannotation:IsUnique", true, out item);
75+
if (found)
76+
{
77+
var value = (UniqueAttribute)item.Value;
78+
columnStatement.ColumnConstraints.Add(new UniqueConstraint
79+
{
80+
OnConflict = value.OnConflict
81+
});
82+
}
83+
}
6984
}
7085
}

0 commit comments

Comments
 (0)