This project is read-only.

Composite key in Orchard

Topics: Core, General, Troubleshooting
Oct 28, 2013 at 4:48 PM
Is it possible to insert a multi column key in Orchard?


Given the following classes:

public class Class1Record
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Password { get; set; }
public class Class2Record
    public virtual int Id { get; set; }
    public virtual string Description { get; set; }
public class ClassRelationRecord
    public virtual int Id { get; set; }
    public virtual Class1Record Class2Record { get; set; }
    public virtual Class2Record Class1Record { get; set; }
I would like to have a table called "ClassRelationRecord" where Id is primary key and (Class1Record _Id, Class2Record_Id) is a multi column unique identifier.
Oct 28, 2013 at 5:32 PM
No, but that doesn't prevent you from setting up uniqueness constraints.
Oct 29, 2013 at 8:46 AM
Ok, and How can I set a uniquess constraint on multiple columns (Properties)?

Thanks for the reply.
Oct 30, 2013 at 7:58 AM
In the DB itself. I don't think migrations have this feature right now.
Oct 30, 2013 at 8:49 AM
If using sql server, you can use this in your migration
SchemaBuilder.ExecuteSql("ALTER TABLE Datwendo_Commerce_ProductPriceListPartRecord ADD CONSTRAINT uc_pl_currency_prod UNIQUE (Product_Id,Currency_Id,PriceList_Id)");
Oct 30, 2013 at 9:01 AM
Good point.
Oct 30, 2013 at 11:59 PM