Linq for Oracle: Value cannot be null in Hierarchy table

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
dqminh
Posts: 28
Joined: Wed 12 Nov 2008 01:31

Linq for Oracle: Value cannot be null in Hierarchy table

Post by dqminh » Mon 01 Dec 2008 11:15

Hi,

When call the delete method in hierarchy table, it will throw an exception Value cannot be null. Step for reproduce error:

1. Create table Dealer

Code: Select all

CREATE TABLE v2_p_Dealer(
    DealerCode      VARCHAR2(30)      NOT NULL,
    ParentCode      VARCHAR2(30),
    DealerName      NVARCHAR2(256)    NOT NULL,
    CONSTRAINT v2_PK05 PRIMARY KEY (DealerCode)
)
;
Note that ParentCode is nullable.

2. Use Entity Developer to generate linq file (C#)

3. Insert to database a new row

3. Call the delete method

Code: Select all

PartDataContext db = new PartDataContext();
Dealer d = db.Dealers.SingleOrDefault(p => p.Code == Code);
if (d != null)
{
	db.Dealers.DeleteOnSubmit(d);
	db.SubmitChanges();
}
That will throw exception

4. In generated file, make a small change

Code: Select all

[Association(Name = "Dealer_Dealer", Storage = "_Dealer1", ThisKey = "ParentCode", IsForeignKey = true)]
public Dealer Dealer1
{
	get
	{
		return this._Dealer1.Entity;
	}
	set
	{
	...
	}
}
become

Code: Select all

[Association(Name = "Dealer_Dealer", Storage = "_Dealer1", ThisKey = "ParentCode", IsForeignKey = true)]
public Dealer Dealer1
{
	get
	{
		if (!string.IsNullOrEmpty(this.ParentCode)) return this._Dealer1.Entity;
		return null;
	}
	set
	{
	...
	}
}
then it works.

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

Post by AndreyR » Mon 01 Dec 2008 12:38

Please post definitions of the foreign key constraint and the table taking part in the reference.

dqminh
Posts: 28
Joined: Wed 12 Nov 2008 01:31

Post by dqminh » Tue 02 Dec 2008 02:05

The reference here:

Code: Select all

ALTER TABLE v2_p_Dealer ADD CONSTRAINT Refv2_p_Dealer41 
    FOREIGN KEY (ParentCode)
    REFERENCES v2_p_Dealer(DealerCode)
;

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

Post by AndreyR » Tue 02 Dec 2008 07:19

Please send me (andreyr * devart * com) an e-mail with your forum nickname, and I will send you the workaround.

Post Reply