-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainViewModel.cs
48 lines (45 loc) · 2.14 KB
/
MainViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using DevExpress.Mvvm;
using DevExpress.Xpf.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace EFCoreIssues {
public class MainViewModel : ViewModelBase {
[DevExpress.Mvvm.DataAnnotations.Command]
public void FetchRows(DevExpress.Mvvm.Xpf.FetchRowsAsyncArgs args) {
args.Result = Task.Run<DevExpress.Xpf.Data.FetchRowsResult>(() =>
{
var context = new EFCoreIssues.Issues.IssuesContext();
var queryable = context.Issues.AsNoTracking()
.SortBy(args.SortOrder, defaultUniqueSortPropertyName: nameof(EFCoreIssues.Issues.Issue.Id))
.Where(MakeFilterExpression((DevExpress.Data.Filtering.CriteriaOperator)args.Filter));
return queryable.Skip(args.Skip).Take(args.Take ?? 100).ToArray();
});
}
[DevExpress.Mvvm.DataAnnotations.Command]
public void GetTotalSummaries(DevExpress.Mvvm.Xpf.GetSummariesAsyncArgs args) {
args.Result = Task.Run(() =>
{
var context = new EFCoreIssues.Issues.IssuesContext();
var queryable = context.Issues.Where(MakeFilterExpression((DevExpress.Data.Filtering.CriteriaOperator)args.Filter));
return queryable.GetSummaries(args.Summaries);
});
}
System.Linq.Expressions.Expression<System.Func<EFCoreIssues.Issues.Issue, bool>> MakeFilterExpression(DevExpress.Data.Filtering.CriteriaOperator filter) {
var converter = new DevExpress.Xpf.Data.GridFilterCriteriaToExpressionConverter<EFCoreIssues.Issues.Issue>();
return converter.Convert(filter);
}
System.Collections.IList _Users;
public System.Collections.IList Users
{
get
{
if(_Users == null && !IsInDesignMode) {
var context = new EFCoreIssues.Issues.IssuesContext();
_Users = context.Users.Select(user => new { Id = user.Id, Name = user.FirstName + " " + user.LastName }).ToArray();
}
return _Users;
}
}
}
}