I've created a new Entity Object:
mplToCreate = this._context.MasterPartsList.CreateOBject();
then, I want to set the parentPnID
to an existing item's property that I tried querying for using the following IQueryable
expression:
mplToCreate.parentPnID = this._context.MasterPartNumbers.FirstOrDefault(x => x.pn == this._selectedItem.Pn).pnID;
But I get a NullReferenceException
at that line. (I know that there exists a pnID
in MasterPartNumbers
that matches this logic.)
Please help me correct my right-hand expression so that I can set the property accordingly.