Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 24bb7a2

Browse files
committed
Strip quoted tables in constraint names
1 parent 8233887 commit 24bb7a2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ServiceStack.OrmLite/OrmLiteDialectProviderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ public virtual string ToCreateTableStatement(Type tableType)
13311331
public virtual string GetUniqueConstraints(ModelDefinition modelDef)
13321332
{
13331333
var constraints = modelDef.UniqueConstraints.Map(x =>
1334-
$"CONSTRAINT {GetUniqueConstraintName(x, GetTableName(modelDef))} UNIQUE ({x.FieldNames.Map(f => modelDef.GetQuotedName(f,this)).Join(",")})" );
1334+
$"CONSTRAINT {GetUniqueConstraintName(x, GetTableName(modelDef).StripQuotes())} UNIQUE ({x.FieldNames.Map(f => modelDef.GetQuotedName(f,this)).Join(",")})" );
13351335

13361336
return constraints.Count > 0
13371337
? constraints.Join(",\n")

tests/ServiceStack.OrmLite.Tests/UniqueConstraintTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,24 @@ public void Does_add_multiple_column_unique_constraint_with_custom_name()
112112
}
113113
}
114114

115+
[UniqueConstraint(nameof(Environment), nameof(Name))]
116+
public class User
117+
{
118+
[AutoId]
119+
public Guid Id { get; set; }
120+
public Guid Environment { get; set; }
121+
public string Name { get; set; }
122+
}
123+
124+
[Test]
125+
public void Can_create_User_table_with_Unique_constraints()
126+
{
127+
OrmLiteUtils.PrintSql();
128+
using (var db = OpenDbConnection())
129+
{
130+
db.DropTable<User>();
131+
db.CreateTableIfNotExists<User>();
132+
}
133+
}
115134
}
116135
}

0 commit comments

Comments
 (0)