Insert failed when associated property is null?

Jul 9, 2008 at 8:30 AM
Currently I'm trying to implement LINQ to SQL with POCO way, so I use ULINQGen to help generate the POCOs, it's great for most of search requirements, but I just met a scenario like this, it's based on Northinwind in your test application:

Order_Detail od = new Order_Detail();
od.OrderId = xxx;
od.UnitPrice = 100;
//set value for other properties


this kind of codes will not work as what i expected, an exception will be throw out. And event if i tried to assign a new instance to Order_Details' Order property, DataContext somehow will also try to add new Order to database too, then an primary key conflict ocurred, that's weired. To make everything works, I need to have a nullable OrderId,  but it's not a real good idea, because it brings difference between database schema and domain entity. Any comments about this?