A Dependent Role has multiple principals with different valu

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
cjbiggs
Posts: 105
Joined: Fri 15 Jan 2010 19:56

A Dependent Role has multiple principals with different valu

Post by cjbiggs » Mon 02 Aug 2010 18:24

I am using Entity Framework 4 to insert values into the table in Postgres. Went I do a Context.SaveChanges I get the following error message from the dotConnect for Postgres Provider.

Referential integrity constraint violation. A Dependent Role has multiple principals with different values.

I have a Dependent/Child Table that has two Foreign Keys that reference the same Primarily Key in the Referenced/Parent Table. The Parent Table has Parent/Child Entities. FK1 reference the Parent Entity and FK2 reference the Child Entity, so the value for both FK1 and FK2 will be different values. Why can't they have different values?

I am using the New build of dotConnect for PostgreSQL 4.95.152

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 04 Aug 2010 12:30

I have made a simple test and everything was inserted correctly. I had two foreign keys pointing from a detail table to master table, like this:

Code: Select all

CREATE TABLE multimaster
(
  id integer NOT NULL,
  "value" text,
  CONSTRAINT multimaster_pkey PRIMARY KEY (id)
);

CREATE TABLE multidetail
(
  id integer NOT NULL,
  parentid integer,
  childid integer,
  "value" text,
  CONSTRAINT multidetail_pkey PRIMARY KEY (id),
  CONSTRAINT multidetail_childid_fkey FOREIGN KEY (childid)
      REFERENCES multimaster (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT multidetail_parentid_fkey FOREIGN KEY (parentid)
      REFERENCES multimaster (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
And the following code succeeded:

Code: Select all

     using (DataModel1Entities db = new DataModel1Entities()) {
        Multimaster mm = new Multimaster
        {
          Id = 3,
          Value = "inserted"
        };
        var masters = db.Multimasters.ToList();
        Multidetail md1 = new Multidetail
        {
          Id = 3,
          Multimaster = masters.Where(m => m.Id == 1).SingleOrDefault(),
          Multimaster1 = mm,
          Value = "inserted"
        };
        Multidetail md2 = new Multidetail
        {
          Id = 4,
          Multimaster = mm,
          Multimaster1 = masters.Where(m => m.Id == 2).SingleOrDefault(),
          Value = "inserted"
        };
        db.AddToMultimasters(mm);
        db.SaveChanges();
      }
    }
Could you please make some changes to this code so that it would reproduce the issue?
A test project illustrating the problem is an option as well.

cjbiggs
Posts: 105
Joined: Fri 15 Jan 2010 19:56

Post by cjbiggs » Fri 17 Dec 2010 22:08

This is the code but everything is working fine now. Thanks for your help with this.

using (DataModel1Entities db = new DataModel1Entities())
{
Multimaster mmparent = new Multimaster
{
Id = 3,
Value = "inserted"
};

Multimaster mmchild1 = new Multimaster
{
Id = 4,
Value = "inserted"
};

Multimaster mmchild2 = new Multimaster
{
Id = 5,
Value = "inserted"
};

Multidetail md1 = new Multidetail
{
Id = 3,
Multimaster = mmchild1,
Multimaster1 = mmparent,
Value = "inserted"
};
Multidetail md2 = new Multidetail
{
Id = 4,
Multimaster = mmchild2,
Multimaster1 = mmparent,
Value = "inserted"
};
db.AddToMultimasters(mmparent);
db.SaveChanges();
}
}

Post Reply