Linq for Oracle: Value cannot be null in Hierarchy table
Posted: 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
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
That will throw exception
4. In generated file, make a small change
become
then it works.
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)
)
;
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();
}
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
{
...
}
}
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
{
...
}
}