-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainViewModel.cs
52 lines (50 loc) · 1.99 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
49
50
51
52
using DevExpress.Mvvm;
using EntityFrameworkIssues.Issues;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
using System;
using System.Linq.Expressions;
using DevExpress.Data.Filtering;
using DevExpress.Xpf.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Data.Entity;
using System.Collections;
namespace EntityFrameworkIssues {
public class MainViewModel : ViewModelBase {
Expression<Func<Issue, bool>> MakeFilterExpression(CriteriaOperator filter) {
var converter = new GridFilterCriteriaToExpressionConverter<Issue>();
return converter.Convert(filter);
}
[Command]
public void FetchPage(FetchPageAsyncArgs args) {
const int pageTakeCount = 5;
args.Result = Task.Run<FetchRowsResult>(() => {
var context = new IssuesContext();
var queryable = context.Issues.AsNoTracking()
.SortBy(args.SortOrder, defaultUniqueSortPropertyName: nameof(Issue.Id))
.Where(MakeFilterExpression((CriteriaOperator)args.Filter));
return queryable.Skip(args.Skip).Take(args.Take * pageTakeCount).ToArray();
});
}
[Command]
public void GetTotalSummaries(GetSummariesAsyncArgs args) {
args.Result = Task.Run(() => {
var context = new IssuesContext();
var queryable = context.Issues.Where(MakeFilterExpression((CriteriaOperator)args.Filter));
return queryable.GetSummaries(args.Summaries);
});
}
IList _Users;
public IList Users {
get
{
if(_Users == null && !DevExpress.Mvvm.ViewModelBase.IsInDesignMode) {
var context = new IssuesContext();
_Users = context.Users.Select(user => new { Id = user.Id, Name = user.FirstName + " " + user.LastName }).ToArray();
}
return _Users;
}
}
}
}