jchapman wrote:
Have you actually tried the scenario you are describing with Linq to Sql? I highly doubt this would be supported there either.
I did a small test project yesterday, and unfortunately it appears to work without problem! Here's the schema and code:
schemaCode:
CREATE TABLE Parent(
Prefix char(2) NOT NULL,
ID int IDENTITY(1,1) NOT NULL,
Name varchar(50) NOT NULL,
CONSTRAINT PK_Parent PRIMARY KEY CLUSTERED (Prefix ASC, ID ASC)
)
CREATE TABLE Child(
Prefix char(2) NOT NULL,
ID int IDENTITY(1,1) NOT NULL,
ParentPrefix char(2) NOT NULL,
ParentID int NOT NULL,
Name varchar(50) NOT NULL,
CONSTRAINT PK_Child PRIMARY KEY CLUSTERED (Prefix ASC, ID ASC)
)
ALTER TABLE Child WITH CHECK ADD CONSTRAINT FK_Child_Parent FOREIGN KEY(ParentPrefix, ParentID)
REFERENCES Parent (Prefix, ID)
And here's the code:
Code:
Dim db As DBDataContext = New DBDataContext
Dim parent = New Parent
parent.Prefix = "SF"
parent.Name = "Father"
db.Parents.InsertOnSubmit(parent)
Dim child = New Child
child.Prefix = "SF"
child.Name = "Son"
parent.Childs.Add(child)
child = New Child
child.Prefix = "SF"
child.Name = "Daughter"
parent.Childs.Add(child)
db.SubmitChanges()
Dim children = From test In db.Childs Where test.Parent Is parent Select test
For Each ctest As Child In children
Debug.WriteLine(String.Format("{0}{1} {2} <= {3}{4} {5}", ctest.Prefix, ctest.ID, ctest.Name, ctest.Parent.Prefix, ctest.Parent.ID, ctest.Parent.Name))
Next
This produces the following output, as expected:
Quote:
SF9 Son <= SF6 Father
SF10 Daughter <= SF6 Father
So, it looks like NHibernate is lagging a bit behind on this one :-(