Beispiel #1
0
        public async Task CreateUpdateReadDeleteAsync()
        {
            Document doc;
            DateTime?initVersion;

            using (IStatelessSession ss = Sfi.OpenStatelessSession())
            {
                ITransaction tx;
                using (tx = ss.BeginTransaction())
                {
                    doc = new Document("blah blah blah", "Blahs");
                    await(ss.InsertAsync(doc));
                    Assert.IsNotNull(doc.LastModified);
                    initVersion = doc.LastModified;
                    Assert.IsTrue(initVersion.HasValue);
                    await(tx.CommitAsync());
                }
                await(Task.Delay(1100));                  // Ensure version increment (some dialects lack fractional seconds).
                using (tx = ss.BeginTransaction())
                {
                    doc.Text = "blah blah blah .... blah";
                    await(ss.UpdateAsync(doc));
                    Assert.IsTrue(doc.LastModified.HasValue);
                    Assert.AreNotEqual(initVersion, doc.LastModified);
                    await(tx.CommitAsync());
                }
                using (tx = ss.BeginTransaction())
                {
                    doc.Text = "blah blah blah .... blah blay";
                    await(ss.UpdateAsync(doc));
                    await(tx.CommitAsync());
                }
                var doc2 = await(ss.GetAsync <Document>("Blahs"));
                Assert.AreEqual("Blahs", doc2.Name);
                Assert.AreEqual(doc.Text, doc2.Text);

                doc2 = (Document)await(ss.CreateQuery("from Document where text is not null").UniqueResultAsync());
                Assert.AreEqual("Blahs", doc2.Name);
                Assert.AreEqual(doc.Text, doc2.Text);

                doc2 = (Document)await(ss.CreateSQLQuery("select * from Document").AddEntity(typeof(Document)).UniqueResultAsync());
                Assert.AreEqual("Blahs", doc2.Name);
                Assert.AreEqual(doc.Text, doc2.Text);

                doc2 = await(ss.CreateCriteria <Document>().UniqueResultAsync <Document>());
                Assert.AreEqual("Blahs", doc2.Name);
                Assert.AreEqual(doc.Text, doc2.Text);

                doc2 = (Document)await(ss.CreateCriteria(typeof(Document)).UniqueResultAsync());
                Assert.AreEqual("Blahs", doc2.Name);
                Assert.AreEqual(doc.Text, doc2.Text);

                using (tx = ss.BeginTransaction())
                {
                    await(ss.DeleteAsync(doc));
                    await(tx.CommitAsync());
                }
            }
        }
Beispiel #2
0
        public async Task RemoveAsync(Transaction entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var transaction = TransactionConverter.Convert(entity);

            await _session.DeleteAsync(transaction);
        }
        public async Task RemoveAsync(Category entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var category = CategoryConverter.Convert(entity);

            try
            {
                await _session.DeleteAsync(category);
            }
            catch (GenericADOException ex) when((ex.InnerException as SQLiteException)?.ErrorCode == SqliteConstraintErrorCode)
            {
                throw new CategoryRelatedTransactionsException(entity);
            }
        }
Beispiel #4
0
        public async Task InitIdAsync()
        {
            Paper paper;

            using (IStatelessSession ss = Sfi.OpenStatelessSession())
            {
                ITransaction tx;
                using (tx = ss.BeginTransaction())
                {
                    paper = new Paper {
                        Color = "White"
                    };
                    await(ss.InsertAsync(paper));
                    Assert.IsTrue(paper.Id != 0);
                    await(tx.CommitAsync());
                }
                using (tx = ss.BeginTransaction())
                {
                    await(ss.DeleteAsync(await(ss.GetAsync <Paper>(paper.Id))));
                    await(tx.CommitAsync());
                }
            }
        }
Beispiel #5
0
        public async Task RefreshAsync()
        {
            Paper paper;

            using (IStatelessSession ss = Sfi.OpenStatelessSession())
            {
                using (ITransaction tx = ss.BeginTransaction())
                {
                    paper = new Paper {
                        Color = "whtie"
                    };
                    await(ss.InsertAsync(paper));
                    await(tx.CommitAsync());
                }
            }
            using (IStatelessSession ss = Sfi.OpenStatelessSession())
            {
                using (ITransaction tx = ss.BeginTransaction())
                {
                    var p2 = await(ss.GetAsync <Paper>(paper.Id));
                    p2.Color = "White";
                    await(ss.UpdateAsync(p2));
                    await(tx.CommitAsync());
                }
            }
            using (IStatelessSession ss = Sfi.OpenStatelessSession())
            {
                using (ITransaction tx = ss.BeginTransaction())
                {
                    Assert.AreEqual("whtie", paper.Color);
                    await(ss.RefreshAsync(paper));
                    Assert.AreEqual("White", paper.Color);
                    await(ss.DeleteAsync(paper));
                    await(tx.CommitAsync());
                }
            }
        }
Beispiel #6
0
 public Task DeleteAsync(object entity, CancellationToken cancellationToken = new CancellationToken())
 {
     EnsureWriteLock();
     return(_session.DeleteAsync(entity, cancellationToken));
 }
Beispiel #7
0
 /// <summary>
 /// Deletes the object asynchronously.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 public Task DeleteAsync(T entity)
 {
     return(Session.DeleteAsync(entity));
 }