Alternative key / unqique in migrations or somewhere else

Topics: General, Writing modules
Aug 9, 2011 at 12:55 PM

Is it possible to define declarative alternative keys/uniques for a table which is created in the migrations?

Aug 9, 2011 at 7:46 PM

What do you mean? Do you mean this?

            SchemaBuilder.AlterTable("ThreadPartRecord", t => t.DropColumn("IsAnswered"));
            SchemaBuilder.AlterTable("PostPartRecord", t => t.AddColumn<int>("MarkedAs"));

Aug 9, 2011 at 11:26 PM

Yes, when you create a column, you can pass in a Lambda that adds to the column:

.Column<string>("Something", c=>c.Unique())

Aug 10, 2011 at 7:27 AM

Yes i saw that but how can i combine this unique to multiple columns? with a alternative key name. So you can have multiple alternative keys for one table.

Aug 10, 2011 at 7:31 AM

I don't think you can do that.

Aug 10, 2011 at 8:43 AM

Too bad. Are there plan to make this possible in the near future? Because i think this is quiet important. This makes sure we can do this declarative instead of maintaining this in code.

Aug 10, 2011 at 9:31 AM

If you need it, implement it and submit a patch.

Aug 10, 2011 at 10:15 AM
Edited Aug 10, 2011 at 10:16 AM

That's a good idea but first i have to dig (learn some stuff) in to the fundamentals of Orchard before i can create this kind of low level functionalities.

Aug 10, 2011 at 8:45 PM

Sure, I wish I could give you a better answer :)

Feb 27, 2012 at 11:14 AM

I've opened an issue for this here.