Hey
I use your latest Components for mySQL in VB.NET 2010
I have created a 1:1 relation for LinQ2MySQL.
In this example I would have a 1:1 relation between Customers and Orders
When running the following LinQ Statement:
Dim Answer = From Query in myDataContext.Customers
LL.DataSource = Answer
Where LL is a 3rd party program, for printing.
When there is a relation, everything works fine. But if the customer has NO Order, then an exeption is thrown, which says, that the ID of the Order can't be NULL (would be right, because the ID field is the primary key of the table)
So, is this a problem in your product? or is this a wanted behaivor, that a 1:1 relation always have to have a child?
Hope you understand - THX
Question to 1:1 relation
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
I will send you a sample in a letter, please check that it was not blocked by your mail filter.
In the sample, two simple tables with one-to-one relation are created, and selects from them are performed via a LinqConnect model. Please specify what should be changed in the sample to reproduce the problem.
The tables are defined as
In the sample, two simple tables with one-to-one relation are created, and selects from them are performed via a LinqConnect model. Please specify what should be changed in the sample to reproduce the problem.
The tables are defined as
Code: Select all
CREATE TABLE oto_parent
(
Id Int(11) PRIMARY KEY,
Val VARCHAR(10)
)
ENGINE = INNODB;
CREATE TABLE oto_child(
Id INT(11) NOT NULL,
Val VARCHAR(10) DEFAULT NULL,
PRIMARY KEY (Id),
CONSTRAINT FK_oto_child_oto_parent_Id FOREIGN KEY (Id)
REFERENCES oto_parent (Id)
)
ENGINE = INNODB;
INSERT INTO oto_parent VALUES (10, 'One child');
INSERT INTO oto_parent VALUES (20, 'No childs');
INSERT INTO oto_child VALUES (10, 'Child row');
Thanks for the sample.
This is working as expected.
So, but I have changed the code from the sample.
After creating the new DataContext, I use:
By looping the second time, it ends up with an error. - This is right so far, because, the second parent haas no child!
But it seems, that this behaivor makes the problem in 3rd party programs.
Because I give them as DataSource the parents, like:
LL.DataSource = parents
When doing this with a one to may relation, then the 3rd party program knows, that if there is no child, go on with the work
But when using a 1:1 relation, I get the error, that Child.ID is not allowed to be NULL.
I also give the other developers a descritption of the problem, because I don't know, where the problem is caused...
THX
This is working as expected.
So, but I have changed the code from the sample.
After creating the new DataContext, I use:
Code: Select all
Dim parents = dc.OtoParents.ToList
For Each Child In parents
Console.WriteLine(Child.OtoChild.Val)
Next
But it seems, that this behaivor makes the problem in 3rd party programs.
Because I give them as DataSource the parents, like:
LL.DataSource = parents
When doing this with a one to may relation, then the 3rd party program knows, that if there is no child, go on with the work
But when using a 1:1 relation, I get the error, that Child.ID is not allowed to be NULL.
I also give the other developers a descritption of the problem, because I don't know, where the problem is caused...
THX
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
This is probably the peculiarity of the third-party tool implementation. In case of one-to-many association it works correctly, as the child property returns an empty collection (which is not null), but for one-to-one association, the child property is a single entity which can be null. Apparently, the tool does not expect such situation.
We can only suggest you to address this issue to the tool developer.
We can only suggest you to address this issue to the tool developer.