示例#1
0
        public void Can_select_with_filter_from_ModelWithOnlyStringFields_table()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                db.CreateTable <ModelWithOnlyStringFields>(true);

                var rowIds = new List <string>(new[] { "id-1", "id-2", "id-3" });

                rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x)));

                var filterRow = ModelWithOnlyStringFields.Create("id-4");
                filterRow.AlbumName = "FilteredName";

                db.Insert(filterRow);

                var rows     = db.Where <ModelWithOnlyStringFields>(new { filterRow.AlbumName });
                var dbRowIds = rows.ConvertAll(x => x.Id);
                Assert.That(dbRowIds, Has.Count.EqualTo(1));
                Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));

                rows     = db.Where <ModelWithOnlyStringFields>(new { filterRow.AlbumName });
                dbRowIds = rows.ConvertAll(x => x.Id);
                Assert.That(dbRowIds, Has.Count.EqualTo(1));
                Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));

                var queryByExample = new ModelWithOnlyStringFields {
                    AlbumName = filterRow.AlbumName
                };
                rows     = db.ByExampleWhere <ModelWithOnlyStringFields>(queryByExample, excludeNulls: true);
                dbRowIds = rows.ConvertAll(x => x.Id);
                Assert.That(dbRowIds, Has.Count.EqualTo(1));
                Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));

                rows = db.Query <ModelWithOnlyStringFields>(
                    "SELECT * FROM ModelWithOnlyStringFields WHERE AlbumName = @AlbumName", new { filterRow.AlbumName });
                dbRowIds = rows.ConvertAll(x => x.Id);
                Assert.That(dbRowIds, Has.Count.EqualTo(1));
                Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));
            }
        }
		public void Can_select_with_filter_from_ModelWithOnlyStringFields_table()
		{
			using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
			{
				db.CreateTable<ModelWithOnlyStringFields>(true);

				var rowIds = new List<string>(new[] { "id-1", "id-2", "id-3" });

				rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x)));

				var filterRow = ModelWithOnlyStringFields.Create("id-4");
				filterRow.AlbumName = "FilteredName";

				db.Insert(filterRow);

				var rows = db.Where<ModelWithOnlyStringFields>(new { filterRow.AlbumName });
				var dbRowIds = rows.ConvertAll(x => x.Id);
				Assert.That(dbRowIds, Has.Count.EqualTo(1));
				Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));

				rows = db.Where<ModelWithOnlyStringFields>(new { filterRow.AlbumName });
				dbRowIds = rows.ConvertAll(x => x.Id);
				Assert.That(dbRowIds, Has.Count.EqualTo(1));
				Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));

				var queryByExample = new ModelWithOnlyStringFields { AlbumName = filterRow.AlbumName };
				rows = db.ByExampleWhere<ModelWithOnlyStringFields>(queryByExample, excludeNulls: true);
				dbRowIds = rows.ConvertAll(x => x.Id);
				Assert.That(dbRowIds, Has.Count.EqualTo(1));
				Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));

				rows = db.Query<ModelWithOnlyStringFields>(
					"SELECT * FROM ModelWithOnlyStringFields WHERE AlbumName = @AlbumName", new { filterRow.AlbumName });
				dbRowIds = rows.ConvertAll(x => x.Id);
				Assert.That(dbRowIds, Has.Count.EqualTo(1));
				Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id));
			}
		}