.net - LINQ - How to modify the select depending on value that DB would return -


i'm relatively new linq , i'm developing .net function instantiates poco selected fields of linq query.

the problem 1 of these fields must transformed "at runtime".

this malfunctioning example:

private shared function getinfectionhistory(hiveid long) ilist(of hiveinfectiondetail)     using db landdatamodelunitofwork = context.createunitofwork             dim historyresult = in db.hiveafbinfections                                 i.hiveid = hiveid                                 select new hiveinfectiondetail {                                     .dateinfected = i.dateinfected,                                     .datecleaned = i.datecleared,                                     .potentialafbinfection = i.potentialinfection,                                     .afbinfection = not i.potentialinfection                                 }             if islistempty(historyresult.tolist())                 return nothing             end if             return historyresult.tolist()         end using end function 

and

private shared function islistempty(of t)(source ienumerable(of t)) boolean         if source nothing             return true         end if         return not source.any()     end function enter code here 

the problematic line when assign value property afbinfection. property opposite value potentialinfection in database. if i.potentialinfection true, property afbinfection should false. doing above cause indexoutofrangeexception - index outside bounds of array not sure linq doing not expression, it's not wish.

is there way modify db field value when storing custom object?

thank you!

try this:

private shared function getinfectionhistory(hiveid long) ilist(of hiveinfectiondetail)     using db landdatamodelunitofwork = context.createunitofwork             dim historyquery1 = in db.hiveafbinfections                                 i.hiveid = hiveid                                 select new {                                     .dateinfected = i.dateinfected,                                     .datecleaned = i.datecleared,                                     .potentialinfection = i.potentialinfection                                 }             dim historyquery2 = in historyquery1.toarray()                                 select new hiveinfectiondetail {                                     .dateinfected = i.dateinfected,                                     .datecleaned = i.datecleaned,                                     .potentialafbinfection = i.potentialinfection,                                     .afbinfection = not i.potentialinfection                                 }             dim historyresult = historyquery2.tolist()             if islistempty(historyresult)                 return nothing             end if             return historyresult         end using end function 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -