c# - Setting navigation property in code is giving me a null reference exception -
this question has answer here:
- what nullreferenceexception, , how fix it? 29 answers
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
Post a Comment