@@ -42,16 +42,91 @@ public CoreDatabase(DbContext dbContext) : base(dbContext)
4242 // return new ListViewModel<TEntity> { Results = result, TotalCount = result.Count };
4343 //}
4444
45- public Task < List < TEntity > > GetItemsAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
46- Expression < Func < TEntity , bool > > condition , CancellationToken cancellationToken = default ) => throw new NotImplementedException ( ) ;
45+ public async Task < List < TEntity > > GetItemsAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
46+ Expression < Func < TEntity , bool > > condition , CancellationToken cancellationToken = default )
47+ {
48+ IQueryable < TEntity > query = DbContext . Set < TEntity > ( ) ;
49+
50+ if ( includes != null )
51+ {
52+ query = includes ( query ) ;
53+ }
54+
55+ if ( condition != null )
56+ {
57+ query = query . Where ( condition ) ;
58+ }
4759
48- public Task < TEntity > GetItemByIdAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
49- Expression < Func < TEntity , bool > > condition , CancellationToken cancellationToken = default ) => throw new NotImplementedException ( ) ;
60+ return await query . AsNoTracking ( ) . ToListAsync ( cancellationToken ) ;
61+ }
62+
63+ public async Task < TEntity > GetItemByIdAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
64+ Expression < Func < TEntity , bool > > condition , CancellationToken cancellationToken = default )
65+ {
66+ IQueryable < TEntity > query = DbContext . Set < TEntity > ( ) ;
5067
51- public Task < List < TEntity > > GetOrderedItemsAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
68+ if ( includes != null )
69+ {
70+ query = includes ( query ) ;
71+ }
72+
73+ if ( condition != null )
74+ {
75+ query = query . Where ( condition ) ;
76+ }
77+
78+ return await query . AsNoTracking ( ) . FirstOrDefaultAsync ( cancellationToken ) ;
79+ }
80+
81+ public async Task < List < TEntity > > GetOrderedItemsAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
5282 Expression < Func < TEntity , bool > > conditionWhere , Expression < Func < TEntity , dynamic > > orderBy ,
53- OrderType orderType = OrderType . Ascending , CancellationToken cancellationToken = default ) => throw new NotImplementedException ( ) ;
83+ OrderType orderType = OrderType . Ascending , CancellationToken cancellationToken = default )
84+ {
85+ IQueryable < TEntity > query = DbContext . Set < TEntity > ( ) ;
5486
55- public Task < int > GetItemsCountAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
56- Expression < Func < TEntity , bool > > condition , CancellationToken cancellationToken = default ) => throw new NotImplementedException ( ) ;
87+ if ( includes != null )
88+ {
89+ query = includes ( query ) ;
90+ }
91+
92+ if ( conditionWhere != null )
93+ {
94+ query = query . Where ( conditionWhere ) ;
95+ }
96+
97+ if ( orderBy != null )
98+ {
99+ if ( orderType == OrderType . Ascending )
100+ {
101+ query = query . OrderBy ( orderBy ) ;
102+ }
103+
104+ if ( orderType == OrderType . Descending )
105+ {
106+ query = query . OrderByDescending ( orderBy ) ;
107+ }
108+ }
109+
110+ return await query
111+ . AsNoTracking ( )
112+ . ToListAsync ( cancellationToken ) ;
113+ }
114+
115+ public async Task < int > GetItemsCountAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
116+ Expression < Func < TEntity , bool > > condition , CancellationToken cancellationToken = default )
117+ {
118+ IQueryable < TEntity > query = DbContext . Set < TEntity > ( ) ;
119+
120+ if ( includes != null )
121+ {
122+ query = includes ( query ) ;
123+ }
124+
125+ if ( condition != null )
126+ {
127+ query = query . Where ( condition ) ;
128+ }
129+
130+ return await query . AsNoTracking ( ) . CountAsync ( cancellationToken ) ;
131+ }
57132}
0 commit comments