-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainWindow.xaml.vb
54 lines (49 loc) · 2.4 KB
/
MainWindow.xaml.vb
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
53
54
Imports EntityFrameworkIssues.Issues
Imports System
Imports System.Linq.Expressions
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpf.Data
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Data.Entity
Imports DevExpress.Xpf.Grid
Class MainWindow
Public Sub New()
InitializeComponent()
Dim source = New PagedAsyncSource With {
.ElementType = GetType(Issue),
.KeyProperty = NameOf(Issue.Id),
.PageNavigationMode = PageNavigationMode.ArbitraryWithTotalPageCount
}
AddHandler source.FetchPage, AddressOf OnFetchPage
AddHandler source.GetTotalSummaries, AddressOf OnGetTotalSummaries
grid.ItemsSource = source
LoadLookupData()
End Sub
Private Function MakeFilterExpression(ByVal filter As CriteriaOperator) As Expression(Of Func(Of Issue, Boolean))
Dim converter = New GridFilterCriteriaToExpressionConverter(Of Issue)()
Return converter.Convert(filter)
End Function
Private Sub OnFetchPage(ByVal sender As Object, ByVal e As FetchPageAsyncEventArgs)
Const pageTakeCount As Integer = 5
e.Result = Task.Run(Of FetchRowsResult)(Function()
Dim context = New IssuesContext()
Dim queryable = context.Issues.AsNoTracking().SortBy(e.SortOrder, defaultUniqueSortPropertyName:=NameOf(Issue.Id)).Where(MakeFilterExpression(CType(e.Filter, CriteriaOperator)))
Return queryable.Skip(e.Skip).Take(e.Take * pageTakeCount).ToArray()
End Function)
End Sub
Private Sub OnGetTotalSummaries(ByVal sender As Object, ByVal e As GetSummariesAsyncEventArgs)
e.Result = Task.Run(Function()
Dim context = New IssuesContext()
Dim queryable = context.Issues.Where(MakeFilterExpression(CType(e.Filter, CriteriaOperator)))
Return queryable.GetSummaries(e.Summaries)
End Function)
End Sub
Private Sub LoadLookupData()
Dim context = New IssuesContext()
usersLookup.ItemsSource = context.Users.[Select](Function(user) New With {
.Id = user.Id,
.Name = user.FirstName & " " + user.LastName
}).ToArray()
End Sub
End Class