c# - LINQ statement broke after upgrading to .NET Core 1.1 Preview 1 -
i have asp.net core application tracks work crews. workcrewmembers
class contains crew members. has key workcrew
class has clumsy list of timespan?
fields specifying when crew starts working on specific days of week: sunstart, monstart, tuestart, wedstart, thustart, fristart, satstart
. classes generated legacy database. have following code working happily in asp.net core 1.0.1
public class program { public static void main(string[] args) { using (dbcontext context = new dbcontext()) { var lstworkcrew = (from m in context.workcrewmembers m.workcrew.todaystarttime() != null select m.workcrewid).tolist(); console.writeline($"today {lstworkcrew.count} work crews"); } } } public partial class workcrew { public timespan? todaystarttime() { timespan?[] starts = { sunstart, monstart, tuestart, wedstart, thustart, fristart, satstart }; int dayofweek = (int)datetime.now.dayofweek; return starts[dayofweek]; } }
however, when upgraded packages 1.1, getting following error in line m.workcrew.todaystarttime()
:
unhandled exception: system.argumentexception: method 'system.nullable`1[system.timespan] todaystarttime()' declared on type 'workcrew' cannot called instance of type 'system.int32'
interesting if from w in context.workcrew w.todaystarttime() != null select w
works fine.
is breaking change in 1.1? or should throw exception earlier because code not legit? or bug microsoft fix?
it appears order of select
, where
somehow inverted in linq notation , got select first returned id. explains why works if select item , not id.
i think if change
context.workcrewmembers .where(m => m.workcrew.todaystarttime() != null) .select(m => m.workcrewid) .tolist();
it work properly.
i prefer notation :)
Comments
Post a Comment