c# - Setting navigation property in code is giving me a null reference exception -


this question has answer here:

when create new object of type orderdetail this:

orderdetail orderdetail = new orderdetail(); 

and try set 1 of reference properties this:

orderdetail.material.description = "test material name"; 

i exception: object reference not set instance of object.

my ultimate goal here create empty list of type orderdetail , manually add few line items it. material navigation property , has description. want able set it.

this post not duplicate. know null reference exception is, i'm confused why happening when trying set navigation property.

you can in 1 go:

orderdetail orderdetail = new orderdetail() {     material = new material()      {          description = "test material name"        } }; 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -