asp.net - Updating an item using LINQ -
i wish update item using linq. tried query.
string option = "new value here"; (jt.summaryspecs.select(x => x.docspecs) .firstordefault() .where( y => y.delitemid == docspc.delitemid && y.itemcode == docspc.itemcode ) .firstordefault().finishingoptionsdesc[0] ) = option;
i wish update value of "finishingoptiondesc," collection of string values wish update 1st one.
but code above not working.
the classes attributes:
"summaryspecs.cs" public docspec[] docspecs { get; set; } "docspecs.cs" public string[] finishingoptionsdesc { get; set; }
my concern update finishingoptiondesc 1st string.
thanks
the part of code prevents snippet working select(/*...*/)
method. creates new reference , takes execution out of expression tree object context.
you have write this:
jt.summaryspecs .where(y => y.docspecs.first().delitemid = docspc.delitemid && y.docspecs.first().itemcode == docspc.itemcode) .first().docspecs.first().finishingoptionsdesc.first() = option;
it not beautyfull, way achieve goal. more pretty code use qes:
(from item in jt.summaryspecs let searchitem = item.docspecs.first() searchitem.delitemid = docspc.delitemid && searchitem.itemcode = docspc.itemcode select item) .first().docspecs.first().finishinoptionsdesc.first() = option;
this way ensures, "do not leave expression tree" until end of statement, can modify reference directly, without loosing given data.
Comments
Post a Comment