|
2 | 2 | using System.Data.Entity.Core.Metadata.Edm; |
3 | 3 | using System.Globalization; |
4 | 4 | using System.Linq; |
| 5 | +using SQLite.CodeFirst.Extensions; |
5 | 6 | using SQLite.CodeFirst.Statement; |
6 | 7 | using SQLite.CodeFirst.Statement.ColumnConstraint; |
7 | 8 |
|
@@ -37,6 +38,7 @@ private IEnumerable<ColumnStatement> CreateColumnStatements() |
37 | 38 | AdjustDatatypeForAutogenerationIfNecessary(property, columnStatement); |
38 | 39 | AddNullConstraintIfNecessary(property, columnStatement); |
39 | 40 | AddUniqueConstraintIfNecessary(property, columnStatement); |
| 41 | + AddCollationConstraintIfNecessary(property, columnStatement); |
40 | 42 |
|
41 | 43 | yield return columnStatement; |
42 | 44 | } |
@@ -68,17 +70,21 @@ private static void AddNullConstraintIfNecessary(EdmProperty property, ColumnSta |
68 | 70 | } |
69 | 71 | } |
70 | 72 |
|
| 73 | + private static void AddCollationConstraintIfNecessary(EdmProperty property, ColumnStatement columnStatement) |
| 74 | + { |
| 75 | + var value = property.GetCustomAnnotation<CollateAttribute>(); |
| 76 | + if (value != null) |
| 77 | + { |
| 78 | + columnStatement.ColumnConstraints.Add(new CollateConstraint { CollationFunction = value.Collation }); |
| 79 | + } |
| 80 | + } |
| 81 | + |
71 | 82 | private static void AddUniqueConstraintIfNecessary(EdmProperty property, ColumnStatement columnStatement) |
72 | 83 | { |
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) |
| 84 | + var value = property.GetCustomAnnotation<UniqueAttribute>(); |
| 85 | + if (value != null) |
76 | 86 | { |
77 | | - var value = (UniqueAttribute)item.Value; |
78 | | - columnStatement.ColumnConstraints.Add(new UniqueConstraint |
79 | | - { |
80 | | - OnConflict = value.OnConflict |
81 | | - }); |
| 87 | + columnStatement.ColumnConstraints.Add(new UniqueConstraint { OnConflict = value.OnConflict }); |
82 | 88 | } |
83 | 89 | } |
84 | 90 | } |
|
0 commit comments