I have a problem with Pocos and nullable foreign keys . I have 2 tables (orders and products) each table have a composite primary key (orderid,orderid2) and (productid,productid
I am assuming that you are using this poco entity generotor, or doing some similar relationship fixing. If so, it is a bug AND you are doing something wrong (i.e. there are ways to do what you want without hitting the said bug).
If you use:
order.Product = product;
instead of
product.Orders.Add(order);
it'd do what you want.
The problem is in FixupProducts method of the Order object (or rather in its interaction with productid setter). Fixup method calls productid setter, and the setter sets Product to null, and when the Fixup method goes on to set productid2, it takes the null pointer exception trying to use that Product.
Of course you can hit similar issues in other cases (although I cannot think of any right now). I'm sure you can find a proper solution if you take a look at the generated classes. Off the top of my head I'd say skipping the setter in fixups would solve the problem but I haven't thought of the implications or tested this so try at your own risk.
Try replacing:
productid = Product.productid;
productid2 = Product.productid2;
with
_productid = Product.productid;
_productid2 = Product.productid2;
I had to correct the poco TT :
Chage the lines (381,441 and 475) :
<#=code.Escape(dependentProperty)#> = <#=code.Escape(navProperty)#>.<#=code.Escape(principalProperty)#>;
by the line :
<#=code.FieldName(dependentProperty)#> = <#=code.Escape(navProperty)#>.<#=code.Escape(principalProperty)#>;