Details
Description
Hi,
Note: You can find the full project attached, I only post excerpts here.
I have two relations (foreign keys) in my Branch class:
<column name="CustomerId" required="true" hidden="true" type="INTEGER" />
<column name="LocationId" required="true" hidden="true" type="INTEGER" />
<!-- Backreference to Customer -->
<foreign-key foreignTable="Customers" name="Customer" onDelete="none">
<reference local="CustomerId" foreign="Id"/>
</foreign-key>
<!-- Reference to the branch location -->
<foreign-key foreignTable="Locations" name="Location" onDelete="none">
<reference local="LocationId" foreign="Id"/>
</foreign-key>
In the Customer class I defined an iforeign-key because I need the Branches collection in this class, but I didn't need a Branches collection y my Location class.
If I run the following test:
aCustomer = new CustomerFactory( context ).CreateObject();
aCustomer.Code = "99999";
aCustomer.Name = "Carlos Peix";
aLocation = new LocationFactory( context ).CreateObject();
aLocation.Code = "HERE";
aBranch = new BranchFactory( context ).CreateObject();
aBranch.Code = "99999";
aBranch.Name = "Praxia";
aBranch.Location = aLocation;
aCustomer.AddBranch( aBranch );
context.SaveChanges();
I get a SQLServer foreign key violation caused by the following statement:
08:42:52,842: INSERT INTO Branches (Code, Name, CustomerId, LocationId) VALUES (@Code, @Name, @CustomerId, @LocationId)
08:42:52,842: @Code = 99999
08:42:52,842: @Name = Praxia
08:42:52,842: @CustomerId = 3
08:42:52,842: @LocationId = -1
As you can see, the LocationId field contains his default value.
If I uncomment de iforeign-key relation in the Locations class which defines the Branches collection I obtain a green bar.
I suppose that this is a bug, right now I can workaround this defining this iforeing-key.
Thanks
Carlos
Thanks for reporting this. It is a known bug that has been discussed on the mailing list but somehow I forgot to add it to Jira. It would be great if we could fix this but unfortunately I currently don't know how.