public async Task Delete_TestAsync() { var lst = Mocker.GetCExtEntities(); var trans = await _transaction.BeginTransactionAsync <CExtEntity>().ConfigureAwait(false); try { await _database.BatchAddAsync(lst, "Tests", trans).ConfigureAwait(false); await trans.CommitAsync().ConfigureAwait(false); } catch { await trans.RollbackAsync().ConfigureAwait(false); throw; } await _database.DeleteAsync <CExtEntity>(e => SqlStatement.In(e.Id, false, lst.Select(e => (object)e.Id).ToArray())).ConfigureAwait(false); long count = await _database.CountAsync <CExtEntity>(e => SqlStatement.In(e.Id, true, lst.Select(e => (object)e.Id).ToArray()), null).ConfigureAwait(false); Assert.True(count == 0); }
/// <summary> /// GetByIdsAsync /// </summary> /// <param name="userIds"></param> /// <param name="transContext"></param> /// <returns></returns> /// <exception cref="CacheException"></exception> /// <exception cref="DatabaseException"></exception> public async Task <IEnumerable <User> > GetByIdsAsync(IEnumerable <long> userIds, TransactionContext?transContext = null) { return(await TryCacheAsideAsync( nameof(User.Id), userIds, db => { return db.RetrieveAsync <User>(u => SqlStatement.In(u.Id, true, userIds), transContext); }).ConfigureAwait(false)); }
public async Task Test_8_LastTimeTestAsync() { IDatabase database = _sqlite; ITransaction transaction = _sqlIteTransaction; PublisherEntity_Client item = Mocker.MockOnePublisherEntity_Client(); await database.AddAsync(item, "xx", null).ConfigureAwait(false); PublisherEntity_Client?fetched = await database.ScalarAsync <PublisherEntity_Client>(item.Id, null).ConfigureAwait(false); Assert.Equal(item.LastTime, fetched !.LastTime); fetched.Name = "ssssss"; await database.UpdateAsync(fetched, "xxx", null).ConfigureAwait(false); fetched = await database.ScalarAsync <PublisherEntity_Client>(item.Id, null).ConfigureAwait(false); //await database.AddOrUpdateAsync(item, "ss", null); fetched = await database.ScalarAsync <PublisherEntity_Client>(item.Id, null).ConfigureAwait(false); //Batch List <PublisherEntity_Client>?items = Mocker.GetPublishers_Client(); TransactionContext trans = await transaction.BeginTransactionAsync <PublisherEntity_Client>().ConfigureAwait(false); try { await database.BatchAddAsync <PublisherEntity_Client>(items, "xx", trans).ConfigureAwait(false); IEnumerable <PublisherEntity_Client>?results = await database.RetrieveAsync <PublisherEntity_Client>(item => SqlStatement.In(item.Id, true, items.Select(item => (object)item.Id).ToArray()), trans).ConfigureAwait(false); await database.BatchUpdateAsync <PublisherEntity_Client>(items, "xx", trans).ConfigureAwait(false); List <PublisherEntity_Client>?items2 = Mocker.GetPublishers_Client(); await database.BatchAddAsync <PublisherEntity_Client>(items2, "xx", trans).ConfigureAwait(false); results = await database.RetrieveAsync <PublisherEntity_Client>(item => SqlStatement.In(item.Id, true, items2.Select(item => (object)item.Id).ToArray()), trans).ConfigureAwait(false); await database.BatchUpdateAsync <PublisherEntity_Client>(items2, "xx", trans).ConfigureAwait(false); await transaction.CommitAsync(trans).ConfigureAwait(false); } catch { await transaction.RollbackAsync(trans).ConfigureAwait(false); throw; } finally { } }