I am trying to create entity with two FK from tables Group and Person.
public class Person
{
public virtual int p_id { get; set; }
public virtual string name { get; set; }
public virtual IList<Person> ppl { get; set; }
}
public class Group
{
public virtual int g_id { get; set; }
public virtual string name{ get; set;}
public virtual IList<Group> groups { get; set; }
}
Many-to-many mapping:
HasManyToMany(x => x.ppl)
.Table("gp")
.ParentKeyColumn("g_id")
.ChildKeyColumn("p_id");
HasManyToMany(x => x.groups)
.Table("gp")
.ParentKeyColumn("p_id")
.ChildKeyColumn("g_id")
.Inverse();
Problem is that both constrains in table gp are referencing on table person. Show create table command:
CREATE TABLE `gp` (
`g_id` int(11) NOT NULL,
`p_id` int(11) NOT NULL,
KEY `p_id` (`p_id`),
KEY `g_id` (`g_id`),
CONSTRAINT `FK4B9E89089BCCDC65` FOREIGN KEY (`g_id`) REFERENCES `person` (`p_id`),
CONSTRAINT `FK4B9E8908E34BCD9E` FOREIGN KEY (`p_id`) REFERENCES `person` (`p_id`)
Want to:
CREATE TABLE `gp` (
`g_id` int(11) NOT NULL,
`p_id` int(11) NOT NULL,
KEY `p_id` (`p_id`),
KEY `g_id` (`g_id`),
CONSTRAINT `FK4B9E89089BCCDC65` FOREIGN KEY (`g_id`) REFERENCES `group` (`g_id`),
CONSTRAINT `FK4B9E8908E34BCD9E` FOREIGN KEY (`p_id`) REFERENCES `person` (`p_id`)
I tried to delete Inverse() in group mapping and use it in person table but I got following exception: "The relationship has Inverse specified on both sides". Does anyone knows why are constraints referencing one table?