LINQ query into ObservableCollection?

后端 未结 2 1513
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 04:12

Cast LINQ result to ObservableCollection

Jon Skeet give a great answer in the question ,but I still cannot make my own.

Still new to classes, so I am still i

相关标签:
2条回答
  • 2021-01-19 05:09

    Basically, you need to pass IEnumerable<Staff_Time_TBL> result of the actual query to the database to initialize the ObservableCollection<Staff_Time_TBL> :

    var linqResults = sql.Staff_Time_TBLs
                         .Where(staff => staff.Staff_No == SelectedEmployee.Key &&
                                         staff.Date_Data == filterFrom &&
                                         staff.Date_Data == filterTo);
    
    var observable = new ObservableCollection<Staff_Time_TBL>(linqResults);
    
    0 讨论(0)
  • 2021-01-19 05:14

    You need ObservableComputations. Using this library you can code like this:

    var linqResults = sql.Staff_Time_TBLs
                         .Filtering(staff =>
                            staff.Date_Data > fromDate &&
                            staff.Date_Data < toDate &&
                            staff.Staff_No == employeeNumber);
    

    In code above I assumed sql.Staff_Time_TBLs is ObservableCollection. linqResults is ObservableCollection and reflects all the changes in the sql.Staff_Time_TBLs collection and properties mentioned in the code. Ensure that all properties mentioned in the code above notify of changes through the INotifyPropertyChanged interface.

    0 讨论(0)
提交回复
热议问题