Exemplo n.º 1
0
        public void ExpressionGenerator_DbCaseExpression()
        {
            var    _       = new TestModel();
            var    column1 = _.Column1;
            _Int32 c1      = _Int32.Const(1);
            _Int32 c0      = _Int32.Const(0);

            {
                var expr = Case.On(column1)
                           .When(c1).Then(_Boolean.True)
                           .When(c0).Then(_Boolean.False)
                           .Else(_Boolean.Null);
                var expectedSql =
                    @"CASE `TestModel`.`Column1`
    WHEN 1 THEN 1
    WHEN 0 THEN 0
    ELSE NULL
END CASE";
                VerifyDbExpression(MySqlVersion.LowestSupported, expr.DbExpression, expectedSql);
            }

            {
                var expr = Case.When(column1 == c1).Then(_Boolean.True)
                           .When(column1 == c0).Then(_Boolean.False)
                           .Else(_Boolean.Null);
                var expectedSql =
                    @"CASE
    WHEN (`TestModel`.`Column1` = 1) THEN 1
    WHEN (`TestModel`.`Column1` = 0) THEN 0
    ELSE NULL
END CASE";
                VerifyDbExpression(MySqlVersion.LowestSupported, expr.DbExpression, expectedSql);
            }
        }
Exemplo n.º 2
0
        public async Task <DataSet <SalesOrderInfo> > GetSalesOrderInfoAsync(_Int32 salesOrderID, CancellationToken ct = default(CancellationToken))
        {
            var result = CreateQuery((DbQueryBuilder builder, SalesOrderInfo _) =>
            {
                builder.From(SalesOrderHeader, out var o)
                .LeftJoin(Customer, o.FK_Customer, out var c)
                .LeftJoin(Address, o.FK_ShipToAddress, out var shipTo)
                .LeftJoin(Address, o.FK_BillToAddress, out var billTo)
                .AutoSelect()
                .AutoSelect(c, _.Customer)
                .AutoSelect(shipTo, _.ShipToAddress)
                .AutoSelect(billTo, _.BillToAddress)
                .Where(o.SalesOrderID == salesOrderID);
            });

            await result.CreateChildAsync(_ => _.SalesOrderDetails, (DbQueryBuilder builder, SalesOrderInfoDetail _) =>
            {
                builder.From(SalesOrderDetail, out var d)
                .LeftJoin(Product, d.FK_Product, out var p)
                .AutoSelect()
                .AutoSelect(p, _.Product)
                .OrderBy(d.SalesOrderDetailID);
            }, ct);

            return(await result.ToDataSetAsync(ct));
        }
Exemplo n.º 3
0
        public void ExpressionGenerator_DbCaseExpression()
        {
            var    model   = new TestModel();
            var    column1 = CreateColumn <_Int32>(model, "Column1");
            _Int32 c1      = _Int32.Const(1);
            _Int32 c0      = _Int32.Const(0);

            {
                var expr = Case.On(column1)
                           .When(c1).Then(_Boolean.True)
                           .When(c0).Then(_Boolean.False)
                           .Else(_Boolean.Null);
                var expectedSql =
                    @"CASE [TestModel].[Column1]
    WHEN 1 THEN 1
    WHEN 0 THEN 0
    ELSE NULL
END";
                VerifyDbExpression(SqlVersion.Sql13, expr.DbExpression, expectedSql);
            }

            {
                var expr = Case.When(column1 == c1).Then(_Boolean.True)
                           .When(column1 == c0).Then(_Boolean.False)
                           .Else(_Boolean.Null);
                var expectedSql =
                    @"CASE
    WHEN ([TestModel].[Column1] = 1) THEN 1
    WHEN ([TestModel].[Column1] = 0) THEN 0
    ELSE NULL
END";
                VerifyDbExpression(SqlVersion.Sql13, expr.DbExpression, expectedSql);
            }
        }
Exemplo n.º 4
0
        public Task <DataSet <Address> > GetAddressLookupAsync(_Int32 customerID, CancellationToken ct)
        {
            var result = CreateQuery <Address>((builder, _) =>
            {
                builder.From(CustomerAddress.Where(x => x.CustomerID == customerID), out var ca)
                .InnerJoin(Address, ca.FK_Address, out var a)
                .AutoSelect();
            });

            return(result.ToDataSetAsync(ct));
        }
Exemplo n.º 5
0
        public static DbSet <T> CreateJsonTable <T>(this MySqlSession mySqlSession, string json, string ordinalColumnName)
            where T : Model, new()
        {
            var _ = new T();

            if (!string.IsNullOrEmpty(ordinalColumnName))
            {
                var dataSetOrdinalColumn = new _Int32().AsJsonOrdinality();
                _.AddSystemColumn(dataSetOrdinalColumn, ordinalColumnName);
            }
            var sourceJsonParam = _String.Param(json).AsMySqlJson();

            s_jsonRowSets.Add(_, sourceJsonParam);
            return(_.CreateDbTable(mySqlSession, ModelAliasManager.GetDbAlias(_)));
        }
Exemplo n.º 6
0
        public static DbSet <T> CreateJsonRowSet <T>(this SqlSession sqlSession, string json, string ordinalColumnName)
            where T : class, IEntity, new()
        {
            var _     = new T();
            var model = _.Model;

            if (!string.IsNullOrEmpty(ordinalColumnName))
            {
                var dataSetOrdinalColumn = new _Int32();
                model.AddSystemColumn(dataSetOrdinalColumn, ordinalColumnName);
            }
            var sourceJsonParam = _String.Param(json).AsSqlNVarCharMax();

            s_jsonRowSets.Add(model, sourceJsonParam);
            return(_.CreateDbTable(sqlSession, ModelAliasManager.GetDbAlias(model)));
        }
Exemplo n.º 7
0
        public async Task DbTable_UpdateAsync_self_increment()
        {
            var log = new StringBuilder();

            using (var db = await MockSalesOrder.CreateAsync(CreateDb(log)))
            {
                _Int32 salesOrderId = 1;
                var    dataSet      = await db.SalesOrderHeader.Where(_ => _.SalesOrderID == salesOrderId).ToDataSetAsync();

                Assert.AreEqual(1, dataSet.Count);
                var revisionNumber = dataSet._.RevisionNumber[0];

                await db.SalesOrderHeader.UpdateAsync((m, _) => m.Select(_.RevisionNumber + 1, _.RevisionNumber), _ => _.SalesOrderID == salesOrderId);

                dataSet = await db.SalesOrderHeader.Where(_ => _.SalesOrderID == salesOrderId).ToDataSetAsync();

                Assert.AreEqual(1, dataSet.Count);
                Assert.AreEqual(revisionNumber + 1, dataSet._.RevisionNumber[0]);
            }
        }
Exemplo n.º 8
0
 public PK(_Int32 productCategoryID)
     : base(productCategoryID)
 {
 }
Exemplo n.º 9
0
 public PK(_Int32 salesOrderID)
     : base(salesOrderID)
 {
 }
Exemplo n.º 10
0
 public PK(_Int32 customerID)
     : base(customerID)
 {
 }
Exemplo n.º 11
0
 public PK(_Int32 addressID)
     : base(addressID)
 {
 }
Exemplo n.º 12
0
 public Int32IdentityUpdater(DataSet dataSet, _Int32 identityColumn, Int32 lastInsertId)
     : base(dataSet, identityColumn, lastInsertId)
 {
 }
 public PrimaryKeyMismatchBaseConstructorArgument(_Int32 id1, _Int32 id2)
     : base(id2, id1)
 {
 }
Exemplo n.º 14
0
 public PK(_Int32 customerId)
     : base(customerId)
 {
 }
 public PrimaryKeySortAttributeConflict([Asc][Desc] _Int32 id)
     : base(id)
 {
 }
 public PrimaryKeyInvalidConstructorParam(int id1, _Int32 id2, int id3)
     : base(id2)
 {
 }
Exemplo n.º 17
0
 public PK(_Int32 customerID, _Int32 addressID)
     : base(customerID, addressID)
 {
 }
Exemplo n.º 18
0
 public PK(_Int32 salesOrderID, _Int32 salesOrderDetailID)
     : base(salesOrderID, salesOrderDetailID)
 {
 }
Exemplo n.º 19
0
 public PK(_Int32 id2)
     : base(id2)
 {
 }
Exemplo n.º 20
0
 internal static new TempTableIdentity FromInt32Column(_Int32 column, int seed, int increment)
 {
     return(new TempTableIdentity(column, seed, increment));
 }
Exemplo n.º 21
0
 public PrimaryKeyMissingBaseConstructor(_Int32 id)
 {
 }
 public PrimaryKeyMismatchBaseConstructor(_Int32 id)
     : base()
 {
 }
Exemplo n.º 23
0
 public PK(_Int32 addressId)
     : base(addressId)
 {
 }
Exemplo n.º 24
0
 public PK(_Int32 productDescriptionID)
     : base(productDescriptionID)
 {
 }
Exemplo n.º 25
0
 public Task <DataSet <Movie> > GetMovieAsync(_Int32 id, CancellationToken ct = default(CancellationToken))
 {
     return(Movie.Where(_ => _.ID == id).ToDataSetAsync(ct));
 }