@@ -16,6 +16,8 @@ public override string ToCreateTableStatement(Type tableType)
16
16
var sbConstraints = StringBuilderCacheAlt . Allocate ( ) ;
17
17
var sbMemOptimized = StringBuilderCacheAlt . Allocate ( ) ;
18
18
19
+ var isMemoryTable = tableType . HasAttribute < SqlServerMemoryOptimizedAttribute > ( ) ;
20
+
19
21
var modelDef = OrmLiteUtils . GetModelDefinition ( tableType ) ;
20
22
foreach ( var fieldDef in modelDef . FieldDefinitions )
21
23
{
@@ -37,6 +39,23 @@ public override string ToCreateTableStatement(Type tableType)
37
39
if ( columnDefinition == null )
38
40
continue ;
39
41
42
+ var collationAttribs = fieldDef . PropertyInfo . GetAttributes < SqlServerCollateAttribute > ( ) ;
43
+ if ( collationAttribs . Count > 0 )
44
+ {
45
+ columnDefinition += $ " COLLATE { collationAttribs [ 0 ] . collation } ";
46
+ }
47
+
48
+ if ( isMemoryTable && fieldDef . IsPrimaryKey )
49
+ {
50
+ columnDefinition = columnDefinition . Replace ( "PRIMARY KEY" , "PRIMARY KEY NONCLUSTERED" ) ;
51
+
52
+ var bucketCountAtribs = fieldDef . PropertyInfo . GetAttributes < SqlServerBucketCountAttribute > ( ) ;
53
+ if ( bucketCountAtribs . Count > 0 )
54
+ {
55
+ columnDefinition += $ " HASH WITH (BUCKET_COUNT={ bucketCountAtribs [ 0 ] . count } )";
56
+ }
57
+ }
58
+
40
59
if ( sbColumns . Length != 0 )
41
60
sbColumns . Append ( ", \n " ) ;
42
61
@@ -54,10 +73,10 @@ public override string ToCreateTableStatement(Type tableType)
54
73
sbConstraints . Append ( GetForeignKeyOnUpdateClause ( fieldDef . ForeignKey ) ) ;
55
74
}
56
75
57
- if ( tableType . HasAttribute < SqlServerMemoryOptimizedAttribute > ( ) )
76
+ if ( isMemoryTable )
58
77
{
59
- sbMemOptimized . Append ( " WITH (MEMORY_OPTIMIZED=ON" ) ;
60
78
var attrib = tableType . FirstAttribute < SqlServerMemoryOptimizedAttribute > ( ) ;
79
+ sbMemOptimized . Append ( " WITH (MEMORY_OPTIMIZED=ON" ) ;
61
80
if ( attrib . Durability == SqlServerDurability . SchemaOnly )
62
81
sbMemOptimized . Append ( ", DURABILITY=SCHEMA_ONLY" ) ;
63
82
else if ( attrib . Durability == SqlServerDurability . SchemaAndData )
0 commit comments