예제 #1
0
        public void Insert_Custom_Flat_ColumnName()
        {
            var schema = new DataSchemaBuilder()
                         .AddSqlEntity <Flat_Entity>(cfg => cfg.Field(q => q.Value, cfg => cfg.ColumnName("Custom")))
                         .Build();
            var sqlDataModel = schema.Sql.SqlEntities.OfType <SqlDataModel <Flat_Entity> >().First();

            using (var dataProvider = DataProvider.CreateTestProvider())
            {
                dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@"
					CREATE TABLE {sqlDataModel.StorageModel.DefaultTableName}
					(
						[Custom] INTEGER
					)"                    ));

                var dataSet = new SqlDataSet <Flat_Entity>(sqlDataModel, dataProvider);

                var entity = new Flat_Entity {
                    Value = 5
                };
                dataSet.Insert(entity).Execute();

                using (var result = dataProvider.ExecuteReader(QueryExpression.Select(new[] { QueryExpression.All() }, from: QueryExpression.Table(sqlDataModel.StorageModel.DefaultTableName))))
                {
                    Assert.IsTrue(result.HasRows);
                    Assert.IsTrue(result.Read());
                    Assert.AreEqual(entity.Value, result.GetInt32(0));
                }
            }
        }
예제 #2
0
        public void Select_Inject_Injects_Values()
        {
            var schema = new DataSchemaBuilder()
                         .AddSqlEntity <Flat_Entity>()
                         .Build();
            var sqlDataModel = schema.Sql.SqlEntities.OfType <SqlDataModel <Flat_Entity> >().First();

            using (var dataProvider = DataProvider.CreateTestProvider())
            {
                dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@"
					CREATE TABLE {sqlDataModel.StorageModel.DefaultTableName}
					(
						[Id] INTEGER PRIMARY KEY AUTOINCREMENT,
						[Value] INTEGER
					)"                    ));

                dataProvider.ExecuteNonQuery(QueryExpression.Insert(
                                                 QueryExpression.Table(sqlDataModel.StorageModel.DefaultTableName),
                                                 new[] { QueryExpression.Column("Value") },
                                                 new[] { QueryExpression.Value(1) },
                                                 new[] { QueryExpression.Value(2) }
                                                 ));

                var dataSet = new SqlDataSet <Flat_Entity>(sqlDataModel, dataProvider);
                var entity  = new Flat_Entity();
                dataSet.Select().Inject(entity);

                Assert.AreEqual(1, entity.Id);
                Assert.AreEqual(1, entity.Value);
            }
        }
예제 #3
0
        public void Entity_Delete_Operation_Deletes_Only_Entity_Record()
        {
            var schema = new DataSchemaBuilder()
                         .AddSqlEntity <Flat_Entity>()
                         .Build();
            var sqlDataModel = schema.Sql.SqlEntities.OfType <SqlDataModel <Flat_Entity> >().First();

            using (var dataProvider = DataProvider.CreateTestProvider())
            {
                dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@"
					CREATE TABLE {sqlDataModel.StorageModel.DefaultTableName}
					(
						[Id] INTEGER PRIMARY KEY AUTOINCREMENT,
						[Value] INTEGER
					)"                    ));

                dataProvider.ExecuteNonQuery(QueryExpression.Insert(
                                                 QueryExpression.Table(sqlDataModel.StorageModel.DefaultTableName),
                                                 new[] { QueryExpression.Column("Value") },
                                                 new[] { QueryExpression.Value(5) },
                                                 new[] { QueryExpression.Value(5) }
                                                 ));

                var dataSet = new SqlDataSet <Flat_Entity>(sqlDataModel, dataProvider);
                var entity  = new Flat_Entity {
                    Id = 1
                };
                dataSet.Delete(entity).Execute();

                using (var queryResult = dataProvider.ExecuteReader(QueryExpression.Select(new[] { QueryExpression.All() }, from: QueryExpression.Table(sqlDataModel.StorageModel.DefaultTableName))))
                {
                    Assert.IsTrue(queryResult.HasRows);
                }
            }
        }
예제 #4
0
        public void Insert_Complex_Entity_With_Relationship_View()
        {
            var schema = new DataSchemaBuilder()
                         .AddSqlEntity <Flat_Entity>()
                         .AddSqlEntity <Complex_Entity>()
                         .Build();
            var flatDataModel    = schema.Sql.SqlEntities.OfType <SqlDataModel <Flat_Entity> >().First();
            var complexDataModel = schema.Sql.SqlEntities.OfType <SqlDataModel <Complex_Entity> >().First();

            using (var dataProvider = DataProvider.CreateTestProvider())
            {
                dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@"
					CREATE TABLE {flatDataModel.StorageModel.DefaultTableName}
					(
						[Value] INTEGER,
						[Id] INTEGER PRIMARY KEY AUTOINCREMENT
					)"                    ));
                dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@"
					CREATE TABLE {complexDataModel.StorageModel.DefaultTableName}
					(
						[Value] INTEGER,
						[Flat_Id] INTEGER
					)"                    ));

                var flatDataSet    = new SqlDataSet <Flat_Entity>(flatDataModel, dataProvider);
                var complexDataSet = new SqlDataSet <Complex_Entity>(complexDataModel, dataProvider);

                //  the ID here isn't written to the INSERT query because the ORM see's it as server generated (which it should be)
                var flatEntity = new Flat_Entity {
                    Id = 1, Value = 5
                };
                var complexEntityView = new { Value = 6, FlatId = flatEntity.Id };

                flatDataSet.Insert(flatEntity).Execute();
                complexDataSet.Insert(complexEntityView).Execute();

                using (var result = dataProvider.ExecuteReader(QueryExpression.Select(
                                                                   new[] { QueryExpression.All() },
                                                                   from: QueryExpression.Table(complexDataModel.StorageModel.DefaultTableName),
                                                                   joins: new[]
                {
                    QueryExpression.Join(
                        QueryExpression.Table(flatDataModel.StorageModel.DefaultTableName),
                        QueryExpression.AreEqual(
                            QueryExpression.Column("Flat_Id", QueryExpression.Table(complexDataModel.StorageModel.DefaultTableName)),
                            QueryExpression.Column("Id", QueryExpression.Table(flatDataModel.StorageModel.DefaultTableName))
                            )
                        )
                })))
                {
                    Assert.IsTrue(result.HasRows);
                    Assert.IsTrue(result.Read());
                    Assert.AreEqual(complexEntityView.Value, result.GetInt32(0));
                    Assert.AreEqual(complexEntityView.FlatId, result.GetInt32(1));
                    Assert.AreEqual(flatEntity.Value, result.GetInt32(2));
                    Assert.AreEqual(flatEntity.Id, result.GetInt32(3));
                }
            }
        }
예제 #5
0
        public void Can_Update_Entity_Instance()
        {
            var schema = new DataSchemaBuilder()
                         .AddSqlEntity <Flat_Entity>()
                         .Build();
            var sqlDataModel = schema.Sql.SqlEntities.OfType <SqlDataModel <Flat_Entity> >().First();

            using (var dataProvider = DataProvider.CreateTestProvider())
            {
                dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@"
					CREATE TABLE {sqlDataModel.StorageModel.DefaultTableName}
					(
						[Id] INTEGER PRIMARY KEY AUTOINCREMENT,
						[Value] TEXT
					)"                    ));

                dataProvider.ExecuteNonQuery(QueryExpression.Insert(
                                                 QueryExpression.Table(sqlDataModel.StorageModel.DefaultTableName),
                                                 new[] { QueryExpression.Column("Value") },
                                                 new[] { QueryExpression.Value("Hello") },
                                                 new[] { QueryExpression.Value("Hello") }
                                                 ));

                var dataSet = new SqlDataSet <Flat_Entity>(sqlDataModel, dataProvider);
                var entity  = new Flat_Entity {
                    Id = 2, Value = "World"
                };
                dataSet.Update(entity).Execute();

                using (var result = dataProvider.ExecuteReader(QueryExpression.Select(new[] { QueryExpression.All() }, from: QueryExpression.Table(sqlDataModel.StorageModel.DefaultTableName))))
                {
                    Assert.IsTrue(result.HasRows);
                    Assert.IsTrue(result.Read());
                    Assert.AreEqual("Hello", result.GetString(1));
                    Assert.IsTrue(result.Read());
                    Assert.AreEqual("World", result.GetString(1));
                }
            }
        }