I have created a simple Visual Studio solution that reproduces the problem. It contains a LinqConnect data context with just three tables:
- Customers
Cards, related to Customers with a one-to-one relationship
Orders,related to Customers with a one-to-many relationship
Code: Select all
var dataContext = new CustomersDataContext();
var customer = new Customer()
{
Name = "Customer Smith"
};
customer.Card = new Card()
{
Number = 1234
};
dataContext.Customers.InsertOnSubmit(customer);
dataContext.SubmitChanges();
If I try to set the Card property to an already existing customer record, it works fine. Also, there is no problem when the relationship is one-to-many. Thus the following works perfectly:
Code: Select all
var dataContext = new CustomersDataContext();
var customer = new Customer()
{
Name = "Customer Smith",
};
customer.Orders.Add(new Order()
{
Date = DateTime.Now
});
customer.Orders.Add(new Order()
{
Date = DateTime.Now
});
dataContext.Customers.InsertOnSubmit(customer);
dataContext.SubmitChanges();
Code: Select all
var dataContext = new CustomersDataContext();
var customer = new Customer()
{
Name = "Customer Smith",
};
dataContext.Customers.InsertOnSubmit(customer);
dataContext.SubmitChanges();
customer.Card = new Card()
{
IdCustomer = customer.Id, //FAIL without this (customer.Id is set to zero)
Number = 1234
};
dataContext.SubmitChanges();
The Visual Studio 2010 project is here in case someone wants to take a look, just change the connection string and create the tables in some Oracle server:
http://dl.dropbox.com/u/17125937/DevArt ... veTest.zip
Thank you!