public void Can_Delete_from_basic_persistence_provider()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List <int> {
                    1, 2, 3, 4, 5
                };

                var rows = rowIds.ConvertAll(ModelWithFieldsOfDifferentTypes.Create);

                rows.ForEach(x => { x.Id = (int)db.Insert(x, selectIdentity: true); });

                var deleteRowIds = new List <int> {
                    rows[1].Id, rows[3].Id
                };
                var getRowIds = rows.ConvertAll(x => x.Id);

                rows.Where(row => deleteRowIds.Contains(row.Id)).ToList().ForEach(basicProvider.Delete);

                var providerRows   = basicProvider.GetByIds <ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                var remainingIds = rows.ConvertAll(x => x.Id);
                deleteRowIds.ForEach(x => remainingIds.Remove(x));

                Assert.That(providerRowIds, Is.EquivalentTo(remainingIds));
            }
        }
        public void Can_Delete_from_basic_persistence_provider()
        {
            using (var db = ConnectionString.OpenDbConnection())
            using (var dbCmd = db.CreateCommand())
            {
                dbCmd.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List<int> { 1, 2, 3, 4, 5 };

                var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                rows.ForEach(x => dbCmd.Insert(x));

                var deleteRowIds = new List<int> { 2, 4 };

                foreach (var row in rows)
                {
                    if (deleteRowIds.Contains(row.Id))
                    {
                        basicProvider.Delete(row);
                    }
                }

                var providerRows = basicProvider.GetByIds<ModelWithFieldsOfDifferentTypes>(rowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                var remainingIds = new List<int>(rowIds);
                deleteRowIds.ForEach(x => remainingIds.Remove(x));

                Assert.That(providerRowIds, Is.EquivalentTo(remainingIds));
            }
        }
		public void Can_GetByIds_from_basic_persistence_provider()
		{
			using (var db = ConnectionString.OpenDbConnection())
			{
				db.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

				var basicProvider = new OrmLitePersistenceProvider(db);

				var rowIds = new List<int> { 1, 2, 3, 4, 5 };

				var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

				rows.ForEach(x => db.Insert(x));

				var getRowIds = new[] { 2, 4 };
				var providerRows = basicProvider.GetByIds<ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
				var providerRowIds = providerRows.ConvertAll(x => x.Id);

				Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
			}
		}
示例#4
0
        public void Can_Delete_from_basic_persistence_provider()
        {
            using (var db = ConnectionString.OpenDbConnection())
                using (var dbCmd = db.CreateCommand())
                {
                    dbCmd.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                    var basicProvider = new OrmLitePersistenceProvider(db);

                    var rowIds = new List <int> {
                        1, 2, 3, 4, 5
                    };

                    var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                    rows.ForEach(x => dbCmd.Insert(x));

                    var deleteRowIds = new List <int> {
                        2, 4
                    };

                    foreach (var row in rows)
                    {
                        if (deleteRowIds.Contains(row.Id))
                        {
                            basicProvider.Delete(row);
                        }
                    }

                    var providerRows   = basicProvider.GetByIds <ModelWithFieldsOfDifferentTypes>(rowIds).ToList();
                    var providerRowIds = providerRows.ConvertAll(x => x.Id);

                    var remainingIds = new List <int>(rowIds);
                    deleteRowIds.ForEach(x => remainingIds.Remove(x));

                    Assert.That(providerRowIds, Is.EquivalentTo(remainingIds));
                }
        }
        public void Can_GetByIds_from_basic_persistence_provider()
        {
            using (var db = ConnectionString.OpenDbConnection())
            {
                db.CreateTable <ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List <int> {
                    1, 2, 3, 4, 5
                };

                var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                rows.ForEach(x => db.Insert(x));

                var getRowIds      = new[] { 2, 4 };
                var providerRows   = basicProvider.GetByIds <ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
            }
        }
        public void Can_Delete_from_basic_persistence_provider()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List<int> { 1, 2, 3, 4, 5 };

                var rows = rowIds.ConvertAll(ModelWithFieldsOfDifferentTypes.Create);

                rows.ForEach(x => { x.Id = (int)db.Insert(x, selectIdentity: true); });

                var deleteRowIds = new List<int> { rows[1].Id, rows[3].Id };
                var getRowIds = rows.ConvertAll(x => x.Id);

                rows.Where(row => deleteRowIds.Contains(row.Id)).ToList().ForEach(basicProvider.Delete);

                var providerRows = basicProvider.GetByIds<ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                var remainingIds = rows.ConvertAll(x => x.Id);
                deleteRowIds.ForEach(x => remainingIds.Remove(x));

                Assert.That(providerRowIds, Is.EquivalentTo(remainingIds));
            }
        }