Exception during association fixup with nullable composite foreign keys

雨燕双飞 提交于 2019-12-03 08:29:46

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)#>;

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!