So this is pretty straight forward. I can't seem to find an answer for this on the web.
In Fluent Migrator, I see the option to tag a column with PrimaryKey() but I don't see anything for creating compound primary keys. It doesn't look like there's an overload for PrimaryKey either.
Is this possible?
base.Create.Table(tableName).WithColumn("Id").AsGuid().PrimaryKey().NotNullable().Unique()
.WithColumn("c1").AsGuid().NotNullable().Unique()
.WithColumn("c2").AsString().NotNullable()
.WithColumn("c3").AsString().NotNullable()
.WithColumn("c4").AsDateTime()
|> ignore
In this example I'd like to use c2
and c3
as a composite primary key
In FluentMigrator, you can create a composite primary key like this:
Create.PrimaryKey("PK_Table").OnTable("Table").WithSchema("schemaname")
.Columns([|"Col1"; "Col2"|])
|> ignore
I seem to remember you could just apply the PrimaryKey()
method to multiple columns. So to use c2 and c3 as a composite primary key for example:
base.Create.Table(tableName)
.WithColumn("Id").AsGuid().NotNullable().Unique()
.WithColumn("c1").AsGuid().NotNullable().Unique()
.WithColumn("c2").AsString().NotNullable().PrimaryKey()
.WithColumn("c3").AsString().NotNullable().PrimaryKey()
.WithColumn("c4").AsDateTime()
|> ignore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With