c# - NullReferenceException: Object reference not set to an instance of an object in code first entity framework class -


this question has answer here:

public decimal total  {      { return quantity * pricelist.price; }     set { total = value; } } 

you need change logic:

public decimal total  {       { return quantity * (pricelist == null ? 0 : pricelist.price);}       set { total = value; } } 

total 0 if pricelist null. may want change logic, example, if pricelist null total should null too? changr total type decimal? , return null in case.

edit: assuming here price property "pricelist" non nullable. if nullable, take note of comments made below.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -