public void Dispose()
 {
     using (var dbContext = new TestDbContext())
     {
         dbContext.Database.Delete();
     }
 }
        public void ShouldThrowDbUpdateConcurrencyExceptionIfEditingNestedOutOfDateModel()
        {
            TestNode node;
            using (var db = new TestDbContext())
            {
                node = new TestNode
                {
                    Title = "Hello",
                    OneToManyOwned = new List<OneToManyOwnedModel>
                    {
                        new OneToManyOwnedModel { Title = "Test1" },
                        new OneToManyOwnedModel { Title = "Test2" }
                    }
                };
                db.Nodes.Add(node);
                db.SaveChanges();
            }

            using (var db = new TestDbContext())
            {
                node.OneToManyOwned.First().RowVersion = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 };
                db.UpdateGraph(node);
                db.SaveChanges();
            }
        }
        public void ShouldThrowDbUpdateConcurrencyExceptionWithEmptyRowVersion()
        {
            TestNode node;
            using (var db = new TestDbContext())
            {
                node = new TestNode
                {
                    Title = "Hello",
                    OneToManyOwned = new List<OneToManyOwnedModel>
                    {
                        new OneToManyOwnedModel { Title = "Test1" },
                        new OneToManyOwnedModel { Title = "Test2" }
                    }
                };
                db.Nodes.Add(node);
                db.SaveChanges();
            }

            using (var db = new TestDbContext())
            {
                node.OneToManyOwned.First().RowVersion = null;
                db.UpdateGraph(node, map => map.OwnedCollection(p => p.OneToManyOwned));
                db.SaveChanges();
            }
        }
Exemple #4
0
        public void ShouldSupportGuidKeys()
        {
            var model = new GuidTestNode();
            using (var context = new TestDbContext())
            {
                context.GuidKeyModels.Add(model);
                context.SaveChanges();

                // http://stackoverflow.com/questions/5270721/using-guid-as-pk-with-ef4-code-first
                Assert.IsTrue(Attribute.IsDefined(model.GetType().GetProperty("Id"), typeof(DatabaseGeneratedAttribute)));

                Assert.IsNotNull(model.Id);
                Assert.AreNotEqual(Guid.Empty, model.Id);
            } // simulate detach

            model.OneToOneOwned = new GuidOneToOneOwned();

            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model, map => map.OwnedEntity(g => g.OneToOneOwned));
                context.SaveChanges();

                Assert.IsNotNull(model.OneToOneOwned);
                Assert.IsNotNull(model.OneToOneOwned.Id);
                Assert.AreNotEqual(Guid.Empty, model.OneToOneOwned.Id);
            }
        }
        public void ShouldAddNewItemInOwnedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel { Title = "Hello" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            var newModel = new OneToManyOwnedModel { Title = "Hi" };
            node1.OneToManyOwned.Add(newModel);
            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .OwnedCollection(p => p.OneToManyOwned));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyOwned).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyOwned.Count == 2);
                var owned = context.OneToManyOwnedModels.Single(p => p.Id == newModel.Id);
                Assert.IsTrue(owned.OneParent == node2 && owned.Title == "Hi");
            }
        }
        public void ShouldAddRelationToExistingAssociatedCollection()
        {
            var associated = new OneToManyAssociatedModel { Title = "Second One" };
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    new OneToManyAssociatedModel { Title = "First One" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.OneToManyAssociatedModels.Add(associated);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToManyAssociated.Add(associated);

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedCollection(p => p.OneToManyAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyAssociated.Count == 2);
            }
        }
 public void Initialize()
 {
     //Arrange
     Context = new TestDbContext();
     var uow = new UnitofWork(Context);
     Controller = new UnitofWorkPatternController(uow);
 }
        public void ShouldBeAbleToVisitExpressionsStoredAsProperties()
        {
            var node1 = new TestNode
            {
                Title = "One",
                OneToOneOwned = new OneToOneOwnedModel { Title = "Hello" }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneOwned.Title = "Hey2";

            Lambda = (p => p.OneToOneOwned);
            Expression<Func<IUpdateConfiguration<TestNode>, dynamic>> exp = map => map.OwnedEntity(Lambda);

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, exp);

                context.SaveChanges();
                Assert.IsTrue(context.Nodes
                    .Include(p => p.OneToOneOwned)
                    .Single(p => p.Id == node1.Id)
                    .OneToOneOwned.Title == "Hey2");
            }
        }
        public void ShouldSupportNullValuesInTree()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToOneOwned = null
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            using (var context = new TestDbContext())
            {
                // Setup mapping
                node1 = context.UpdateGraph(node1, map => map
                    .OwnedEntity(p => p.OneToOneOwned, with =>
                        with.OwnedEntity(p => p.OneToOneOneToOneOwned)));

                context.SaveChanges();
                context.Entry(node1).Reload();
                Assert.IsTrue(node1.OneToOneOwned == null);
            }
        }
        public void ShouldAddAssociatedWithoutChangingRequiredAssociate()
        {
            var root = new RootEntity { RequiredAssociate = new RequiredAssociate(), Sources = new List<RootEntity>() };
            var requiredAssociate = new RequiredAssociate();
            using (var context = new TestDbContext())
            {
                context.RootEntities.Add(root);
                context.RequiredAssociates.Add(requiredAssociate);
                context.SaveChanges();
            } // Simulate detach

            var expectedAssociateId = requiredAssociate.Id;
            var owned = new RootEntity { RequiredAssociate = requiredAssociate };
            root.Sources.Add(owned);

            using (var context = new TestDbContext())
            {
                root = context.UpdateGraph(root, map => map.AssociatedCollection(r => r.Sources));
                context.SaveChanges();

                var ownedAfterSave = root.Sources.FirstOrDefault();
                Assert.IsNotNull(ownedAfterSave);
                Assert.IsNotNull(ownedAfterSave.RequiredAssociate);
                Assert.AreEqual(expectedAssociateId, ownedAfterSave.RequiredAssociate.Id);

                var ownedReloaded = context.RootEntities.Single(r => r.Id == ownedAfterSave.Id);
                Assert.IsNotNull(ownedReloaded.RequiredAssociate);
                Assert.AreEqual(expectedAssociateId, ownedReloaded.RequiredAssociate.Id);
            }
        }
        public void ShouldNotUpdateEntitesWithinAnAssociatedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    new OneToManyAssociatedModel { Title = "First One" }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToManyAssociated.First().Title = "This should not overwrite value";

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedCollection(p => p.OneToManyAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToManyAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToManyAssociated.Single().Title == "First One");
            }
        }
        public void ShouldNotUpdatePropertiesOfAnAssociatedEntity()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToOneAssociated = new OneToOneAssociatedModel { Title = "Associated Node" }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneAssociated.Title = "Updated Content";

            using (var context = new TestDbContext())
            {
                context.UpdateGraph(node1);

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToOneAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToOneAssociated.OneParent == node2);
                // should not delete it as it is associated and no cascade rule set.
                Assert.IsTrue(node2.OneToOneAssociated.Title == "Associated Node");
            }
        }
        public void ShouldAddRelationIfPreviousValueWasNullWithCycle()
        {
            GroupedTestNode two;
            GroupedTestNode one;
            using (var context = new TestDbContext())
            {
                var group = new NodeGroup();
                context.NodeGroups.Add(group);
                context.SaveChanges();

                one = new GroupedTestNode { Group = group };
                context.Nodes.Add(one);
                context.SaveChanges();

                two = new GroupedTestNode { Group = group };
                context.Nodes.Add(two);
                context.SaveChanges();

                Assert.AreEqual(2, group.Members.Count);
            } // Simulate detach

            using (var context = new TestDbContext())
            {
                one.Two = two;

                // Setup mapping
                context.UpdateGraph(one, map => map.AssociatedEntity(o => o.Two));
                context.SaveChanges();

                var oneReloaded = context.Nodes.OfType<GroupedTestNode>().Include("Two").Single(n => n.Id == one.Id);
                Assert.IsNotNull(oneReloaded.Two);
                Assert.AreEqual(two.Id, oneReloaded.Two.Id);
            }
        }
        public void ShouldAddRelationIfPreviousValueWasNull()
        {
            var node1 = new TestNode { Title = "New Node" };
            var associated = new OneToOneAssociatedModel { Title = "Associated Node" };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.OneToOneAssociatedModels.Add(associated);
                context.SaveChanges();
            } // Simulate detach

            node1.OneToOneAssociated = associated;

            using (var context = new TestDbContext())
            {
                // Setup mapping
                context.UpdateGraph(node1, map => map
                    .AssociatedEntity(p => p.OneToOneAssociated));

                context.SaveChanges();
                var node2 = context.Nodes.Include(p => p.OneToOneAssociated).Single(p => p.Id == node1.Id);
                Assert.IsNotNull(node2);
                Assert.IsTrue(node2.OneToOneAssociated.OneParent == node2);
            }
        }
Exemple #15
0
        public void ShouldSupportMultipleKeys()
        {
            var model = new MultiKeyModel
            {
                Title = "Hello",
                Date = DateTime.Now,
                KeyPart1 = "A123",
                KeyPart2 = "A234"
            };

            using (var context = new TestDbContext())
            {
                context.MultiKeyModels.Add(model);
                context.SaveChanges();
            } // simulate detach

            model.Date = DateTime.Parse("01/01/2010");
            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model);
                context.SaveChanges();

                context.Entry(model).Reload();
                Assert.IsTrue(model.Date == DateTime.Parse("01/01/2010"));
            }
        }
        public void ShouldAddNewAggregateRoot_Attached()
        {
            var associated = new OneToOneAssociatedModel { Title = "Associated" };
            var manyAssociated = new OneToManyAssociatedModel { Title = "Associated" };
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel { Title = "One" },
                    new OneToManyOwnedModel { Title = "Two" },
                    new OneToManyOwnedModel { Title = "Three" }
                },
                OneToManyAssociated = new List<OneToManyAssociatedModel>
                {
                    manyAssociated
                },
                OneToOneOwned = new OneToOneOwnedModel { Title = "OneToOne" },
                OneToOneAssociated = associated
            };

            using (var context = new TestDbContext())
            {
                context.OneToManyAssociatedModels.Add(manyAssociated);
                context.OneToOneAssociatedModels.Add(associated);

                     node1 = context.UpdateGraph(node1);

                context.SaveChanges();
                Assert.IsNotNull(context.Nodes.SingleOrDefault(p => p.Id == node1.Id));
            }
        }
Exemple #17
0
        public void TestInitialize()
        {
            context = new TestDbContext();
            repo = new MBlogRepository(context);

            for (int i = 1; i <= 10; i++)
                context.Posts.Add(new Post() { Title = "Post " + i, PublishDate = DateTime.UtcNow.AddDays(11 - i) });
        }
 public SqlDataContextFixture()
 {
     using (var dbContext = new TestDbContext())
     {
         dbContext.Database.Delete();
         dbContext.Database.Create();
     }
 }
        public static void InsertTestItems(TestDbContext context)
        {
            var item1 = new Item { Name = "Test Item 1", Description = "Test Item 1" };
            var item2 = new Item { Name = "Test Item 2", Description = "Test Item 2" };

            context.Set<Item>().Add(item1);
            context.Set<Item>().Add(item2);
        }
 public void ShouldThrowIfTypeIsNotKnown()
 {
     using (var context = new TestDbContext())
     {
         context.UpdateGraph(new UnknownType());
         context.SaveChanges();
     }
 }
Exemple #21
0
        public void ShouldSupportInternalKeys()
        {
            using (var context = new TestDbContext())
            {
                var model = context.UpdateGraph(new InternalKeyModel());
                context.SaveChanges();

                Assert.AreNotEqual(0, model.Id);
            }
        }
        public void ShouldUpdateItemInNestedOwnedCollection()
        {
            var node1 = new TestNode
            {
                Title = "New Node",
                OneToManyOwned = new List<OneToManyOwnedModel>
                {
                    new OneToManyOwnedModel
                    {
                        Title = "Hello",
                        OneToManyOneToManyOwned = new Collection<OneToManyOneToManyOwnedModel>
                        {
                            new OneToManyOneToManyOwnedModel {Title = "BeforeUpdate"}
                        }
                    }
                }
            };

            using (var context = new TestDbContext())
            {
                context.Nodes.Add(node1);
                context.SaveChanges();
            } // Simulate detach

            var oneToManyOneToManyOwned = node1.OneToManyOwned.Single().OneToManyOneToManyOwned.Single();
            var expectedId = oneToManyOneToManyOwned.Id;
            const string expectedTitle = "AfterUpdate";
            oneToManyOneToManyOwned.Title = expectedTitle;

            using (var context = new TestDbContext())
            {
                // Setup mapping
                node1 = context.UpdateGraph(node1, map => map.OwnedCollection(p => p.OneToManyOwned,
                                                                              with => with.OwnedCollection(p => p.OneToManyOneToManyOwned)));
                context.SaveChanges();

                Assert.AreEqual(1, node1.OneToManyOwned.Count);
                Assert.AreEqual(1, node1.OneToManyOwned.Single().OneToManyOneToManyOwned.Count);

                oneToManyOneToManyOwned = node1.OneToManyOwned.Single().OneToManyOneToManyOwned.Single();
                Assert.AreEqual(expectedId, oneToManyOneToManyOwned.Id);
                Assert.AreEqual(expectedTitle, oneToManyOneToManyOwned.Title);

                var node1Reloaded = context.Nodes
                        .Include("OneToManyOwned.OneToManyOneToManyOwned")
                        .Single(n => n.Id == node1.Id);

                Assert.AreEqual(1, node1Reloaded.OneToManyOwned.Count);
                Assert.AreEqual(1, node1Reloaded.OneToManyOwned.Single().OneToManyOneToManyOwned.Count);

                oneToManyOneToManyOwned = node1Reloaded.OneToManyOwned.Single().OneToManyOneToManyOwned.Single();
                Assert.AreEqual(expectedId, oneToManyOneToManyOwned.Id);
                Assert.AreEqual(expectedTitle, oneToManyOneToManyOwned.Title);
            }
        }
Exemple #23
0
 public void ShouldThrowExceptionIfAggregateIsNotDetached()
 {
     using (var context = new TestDbContext())
     {
         var node = new TestNode();
         context.Nodes.Add(node);
         node.Title = "Hello";
         context.UpdateGraph(node);
         context.SaveChanges();
     }
 }
		public void MSSQLQuery_SelectWithWhereClause_ReturnsTheRightQuery()
		{
			var expectedQuery = @"SELECT [Id] AS [Id] FROM Users WHERE ([Id] = @Id)";

            TestDbContext context = new TestDbContext();
            var query = context.Query<User>().Where(p => p.Id == 2);
            
            IEntityMapper mapper = context.DatabaseModel.MapperWithType(typeof(User));
            QueryVisitor visitor = new QueryVisitor(mapper, new WhereVisitor(), new ProjectorVisitor());
            //string text = visitor.Translate(query.Expression);

            //Assert.AreEqual(expectedQuery, text);
		}
        public void MSSQLQuery_Select_ReturnsTheRightQuery()
        {
            var expectedQuery = @"SELECT [Id] AS [Id] FROM Users";

            TestDbContext context = new TestDbContext();
            var query = context.Query<User>().Select(p => new { p.Id });

            IEntityMapper mapper = context.DatabaseModel.MapperWithType(typeof(User));
            QueryVisitor visitor = new QueryVisitor(mapper, new WhereVisitor(), new ProjectorVisitor());
            //Tuple<string, IdD text = visitor.Translate(query.Expression);

            //Assert.AreEqual(expectedQuery, text);
        }
        public void TestMethod1()
        {
            using (TestDbContext context = new TestDbContext("ConnectionString"))
            {
                var query = context
                    .Users
                    .Where(p => p.Id == 1);

                foreach (var user in query)
                {
                    Debug.WriteLine(user.Name);
                }
            }
        }
        public void ShouldAddSingleEntity()
        {
            var node1 = new TestNode
            {
                Title = "Hello"
            };

            using (var context = new TestDbContext())
            {
                node1 = context.UpdateGraph(node1);
                context.SaveChanges();
                Assert.IsNotNull(context.Nodes.SingleOrDefault(p => p.Id == node1.Id));
            }
        }
        public void SetupEntities()
        {
            _conn = DbConnectionFactory.CreateTransient();
            _context = new TestDbContext(_conn);

            var b1 = new Backlink
            {
                Url = "http://www.google.com/",
                Snippet = "1 Results"
            };
            _context.Backlinks.Add(b1);

            _context.SaveChanges();
        }
        public void Effort_FilterByDto()
        {
            using (var context = new TestDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                IQueryable<OrderDto> sourceResult = new OrderDto[0]
                    .AsQueryable()
                    .Where(s => s.FullName.EndsWith("Bestellung"))
                    .Map<OrderDto, Order>(context.OrderSet)
                    .ProjectTo<OrderDto>(); // projection added

                var dtos = sourceResult.ToList();

                Assert.AreEqual(2, dtos.Count);
            }
        }
Exemple #30
0
        public void ShouldSupportAddingRootWithGuidKey()
        {
            var model = new GuidTestNode {OneToOneOwned = new GuidOneToOneOwned()};

            using (var context = new TestDbContext())
            {
                model = context.UpdateGraph(model, map => map.OwnedEntity(g => g.OneToOneOwned));
                context.SaveChanges();

                Assert.AreNotEqual(Guid.Empty, model.Id);
                Assert.IsNotNull(model.OneToOneOwned);
                Assert.IsNotNull(model.OneToOneOwned.Id);
                Assert.AreNotEqual(Guid.Empty, model.OneToOneOwned.Id);
            }
        }
 public ApiConfirmationResponsesController(TestDbContext context)
 {
     _context = context;
 }
 public DefaultSettingsCreator(TestDbContext context)
 {
     _context = context;
 }
 public static async Task FirstOrNotFoundAsync_EntityDoesNotExist_ThrowNotFoundException(TestDbContext dbContext)
 {
     try
     {
         var order = await dbContext.SettlementOrders
                     .Include(o => o.IndividualConsumers)
                     .Include(o => o.OrganisationalConsumers)
                     .FirstOrNotFoundAsync(o => o.Id == 999999, nameof(SettlementOrder), 999999, CancellationToken.None);
     }
     catch (NotFoundException)
     {
         ConsoleLoggingHelper.WriteTestResult(nameof(FirstOrNotFoundAsync_EntityDoesNotExist_ThrowNotFoundException), true);
     }
     catch (Exception)
     {
         ConsoleLoggingHelper.WriteTestResult(nameof(FirstOrNotFoundAsync_EntityDoesNotExist_ThrowNotFoundException), false);
     }
 }
Exemple #34
0
 public StudentController(TestDbContext context)
 {
     _context = context;
 }
Exemple #35
0
 public LienHeClientController()
 {
     db = new TestDbContext();
 }
Exemple #36
0
 public TestController(TestDbContext context)
 {
     _context = context;
 }
 public QuestionRepository(TestDbContext ctx)
 {
     context = ctx;
 }
 public CreateCustomerCommandHandler(IMapper mapper, TestDbContext context)
 {
     this.mapper  = mapper;
     this.context = context;
 }
Exemple #39
0
 public UserRepositories(TestDbContext context) : base(context)
 {
     db = context;
 }
Exemple #40
0
 public TestDbController(TestDbContext testDbContext)
 {
     db = testDbContext;
 }
 public UserPhotosController(TestDbContext context)
 {
     _context = context;
 }
        public static async Task FirstOrDefaultAsync_EntityDoesNotExist_ReturnDefault(TestDbContext dbContext)
        {
            try
            {
                var order = await dbContext.SettlementOrders
                            .Include(o => o.IndividualConsumers)
                            .Include(o => o.OrganisationalConsumers)
                            .FirstOrDefaultAsync(o => o.Id == 999999);

                if (order == default)
                {
                    ConsoleLoggingHelper.WriteTestResult(nameof(FirstOrDefaultAsync_EntityDoesNotExist_ReturnDefault), true);
                }
            }
            catch (Exception)
            {
                ConsoleLoggingHelper.WriteTestResult(nameof(FirstOrNotFoundAsync_EntityDoesNotExist_ThrowNotFoundException), false);
            }
        }
Exemple #43
0
 public CapThiController()
 {
     db = new TestDbContext();
 }
 public ResourceOwnerPasswordValidator(TestDbContext dbContext, ISystemClock clock)
 {
     _dbContext = dbContext;
     _clock     = clock;
 }
Exemple #45
0
 public DefaultEditionCreator(TestDbContext context)
 {
     _context = context;
 }
Exemple #46
0
 public TaskStartedMessageHandler(TestDbContext dbContext, ILogger <TaskStartedMessageHandler> logger)
 {
     _dbContext = dbContext;
     _logger    = logger;
 }
Exemple #47
0
 public BlogService(TestDbContext context)
 {
     _context = context;
 }
 public TextMessageRepo()
 {
     _context = new TestDbContext();
     _table   = (_context as TestDbContext).TextMessages;
 }
 public TestRepository(TestDbContext ctx)
 {
     context = ctx;
 }
Exemple #50
0
        public void Test03()
        {
            var sqlextMax112 = g.sqlserver.Select <EdiItem>()
                               .GroupBy(a => a.Id)
                               .ToSql(a => new
            {
                Id     = a.Key,
                EdiId1 = SqlExt.Max(a.Key).Over().PartitionBy(new { a.Value.EdiId, a.Value.Id }).OrderByDescending(new { a.Value.EdiId, a.Value.Id }).ToValue(),
                EdiId2 = SqlExt.Max(a.Key).Over().PartitionBy(a.Value.EdiId).OrderByDescending(a.Value.Id).ToValue(),
                EdiId3 = SqlExt.Sum(a.Key).ToValue(),
                EdiId4 = a.Sum(a.Key)
            });

            Assert.Throws <ArgumentException>(() => g.sqlite.Update <testUpdateNonePk>().SetSource(new testUpdateNonePk()).ExecuteAffrows());

            g.sqlite.Insert(new testInsertNullable()).NoneParameter().ExecuteAffrows();
            var ddlsql = g.sqlite.CodeFirst.GetComparisonDDLStatements(typeof(testInsertNullable), "tb123123");

            Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""tb123123"" (  
  ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT, 
  ""str1"" NVARCHAR(255) NOT NULL, 
  ""int1"" INTEGER NOT NULL, 
  ""int2"" INTEGER 
) 
;
", ddlsql);

            var select16Sql1 = g.sqlite.Select <userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo>()
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => b.userid == a.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => c.userid == b.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => d.userid == c.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => e.userid == d.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => f.userid == e.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => g.userid == f.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => h.userid == g.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => i.userid == h.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => j.userid == i.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => k.userid == j.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => l.userid == k.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => m.userid == l.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => n.userid == m.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => o.userid == n.userid)
                               .InnerJoin((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => p.userid == o.userid)
                               .ToSql((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => p);

            Assert.Equal(@"SELECT p.""userid"" as1, p.""badgenumber"" as2, p.""ssn"" as3, p.""IDCardNo"" as4, p.""name"" as5, p.""title"" as6, p.""birthday"" as7, p.""hiredday"" as8, p.""hetongdate"" as9, p.""street"" as10, p.""zip"" as11, p.""ophone"" as12, p.""pager"" as13, p.""fphone"" as14, p.""CardNo"" as15, p.""email"" as16, p.""idcardvalidtime"" as17, p.""homeaddress"" as18, p.""minzu"" as19, p.""leavedate"" as20, p.""loginpass"" as21, p.""picurl"" as22, p.""managerid"" as23 
FROM ""userinfo"" a 
INNER JOIN ""userinfo"" b ON b.""userid"" = a.""userid"" 
INNER JOIN ""userinfo"" c ON c.""userid"" = b.""userid"" 
INNER JOIN ""userinfo"" d ON d.""userid"" = c.""userid"" 
INNER JOIN ""userinfo"" e ON e.""userid"" = d.""userid"" 
INNER JOIN ""userinfo"" f ON f.""userid"" = e.""userid"" 
INNER JOIN ""userinfo"" g ON g.""userid"" = f.""userid"" 
INNER JOIN ""userinfo"" h ON h.""userid"" = g.""userid"" 
INNER JOIN ""userinfo"" i ON i.""userid"" = h.""userid"" 
INNER JOIN ""userinfo"" j ON j.""userid"" = i.""userid"" 
INNER JOIN ""userinfo"" k ON k.""userid"" = j.""userid"" 
INNER JOIN ""userinfo"" l ON l.""userid"" = k.""userid"" 
INNER JOIN ""userinfo"" m ON m.""userid"" = l.""userid"" 
INNER JOIN ""userinfo"" n ON n.""userid"" = m.""userid"" 
INNER JOIN ""userinfo"" o ON o.""userid"" = n.""userid"" 
INNER JOIN ""userinfo"" p ON p.""userid"" = o.""userid""", select16Sql1);
            var select16Sql2 = g.sqlite.Select <userinfo>()
                               .From <userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo, userinfo>(
                (s, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => s
                .InnerJoin(a => b.userid == a.userid)
                .InnerJoin(a => c.userid == b.userid)
                .InnerJoin(a => d.userid == c.userid)
                .InnerJoin(a => e.userid == d.userid)
                .InnerJoin(a => f.userid == e.userid)
                .InnerJoin(a => g.userid == f.userid)
                .InnerJoin(a => h.userid == g.userid)
                .InnerJoin(a => i.userid == h.userid)
                .InnerJoin(a => j.userid == i.userid)
                .InnerJoin(a => k.userid == j.userid)
                .InnerJoin(a => l.userid == k.userid)
                .InnerJoin(a => m.userid == l.userid)
                .InnerJoin(a => n.userid == m.userid)
                .InnerJoin(a => o.userid == n.userid)
                .InnerJoin(a => p.userid == o.userid)
                )
                               .ToSql((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => p);

            Assert.Equal(@"SELECT p.""userid"" as1, p.""badgenumber"" as2, p.""ssn"" as3, p.""IDCardNo"" as4, p.""name"" as5, p.""title"" as6, p.""birthday"" as7, p.""hiredday"" as8, p.""hetongdate"" as9, p.""street"" as10, p.""zip"" as11, p.""ophone"" as12, p.""pager"" as13, p.""fphone"" as14, p.""CardNo"" as15, p.""email"" as16, p.""idcardvalidtime"" as17, p.""homeaddress"" as18, p.""minzu"" as19, p.""leavedate"" as20, p.""loginpass"" as21, p.""picurl"" as22, p.""managerid"" as23 
FROM ""userinfo"" a 
INNER JOIN ""userinfo"" b ON b.""userid"" = a.""userid"" 
INNER JOIN ""userinfo"" c ON c.""userid"" = b.""userid"" 
INNER JOIN ""userinfo"" d ON d.""userid"" = c.""userid"" 
INNER JOIN ""userinfo"" e ON e.""userid"" = d.""userid"" 
INNER JOIN ""userinfo"" f ON f.""userid"" = e.""userid"" 
INNER JOIN ""userinfo"" g ON g.""userid"" = f.""userid"" 
INNER JOIN ""userinfo"" h ON h.""userid"" = g.""userid"" 
INNER JOIN ""userinfo"" i ON i.""userid"" = h.""userid"" 
INNER JOIN ""userinfo"" j ON j.""userid"" = i.""userid"" 
INNER JOIN ""userinfo"" k ON k.""userid"" = j.""userid"" 
INNER JOIN ""userinfo"" l ON l.""userid"" = k.""userid"" 
INNER JOIN ""userinfo"" m ON m.""userid"" = l.""userid"" 
INNER JOIN ""userinfo"" n ON n.""userid"" = m.""userid"" 
INNER JOIN ""userinfo"" o ON o.""userid"" = n.""userid"" 
INNER JOIN ""userinfo"" p ON p.""userid"" = o.""userid""", select16Sql2);


            var sqlxx = g.pgsql.InsertOrUpdate <userinfo>().SetSource(new userinfo {
                userid = 10
            }).UpdateColumns(a => new { a.birthday, a.CardNo }).ToSql();

            var aff1 = g.sqlite.GetRepository <Edi, long>().Delete(10086);
            var aff2 = g.sqlite.Delete <Edi>(10086).ExecuteAffrows();

            Assert.Equal(aff1, aff2);

            g.sqlserver.Delete <Edi>().Where("1=1").ExecuteAffrows();
            g.sqlserver.Delete <EdiItem>().Where("1=1").ExecuteAffrows();
            g.sqlserver.Insert(new[] { new Edi {
                                           Id = 1
                                       }, new Edi {
                                           Id = 2
                                       }, new Edi {
                                           Id = 3
                                       }, new Edi {
                                           Id = 4
                                       }, new Edi {
                                           Id = 5
                                       } }).ExecuteAffrows();
            g.sqlserver.Insert(new[] {
                new EdiItem {
                    Id = 1, EdiId = 1
                }, new EdiItem {
                    Id = 2, EdiId = 1
                }, new EdiItem {
                    Id = 3, EdiId = 1
                },
                new EdiItem {
                    Id = 4, EdiId = 2
                }, new EdiItem {
                    Id = 5, EdiId = 2
                },
                new EdiItem {
                    Id = 6, EdiId = 3
                }, new EdiItem {
                    Id = 7, EdiId = 3
                },
                new EdiItem {
                    Id = 8, EdiId = 4
                }, new EdiItem {
                    Id = 9, EdiId = 4
                },
                new EdiItem {
                    Id = 10, EdiId = 5
                }, new EdiItem {
                    Id = 11, EdiId = 5
                },
            }).ExecuteAffrows();


            var testStringFormat = g.sqlite.Select <Edi>().First(a => new {
                str  = $"x{a.Id}_{DateTime.Now.ToString("yyyyMM")}z",
                str2 = string.Format("{0}x{0}_{1}z", a.Id, DateTime.Now.ToString("yyyyMM"))
            });



            var sql123 = g.sqlserver.Select <Edi>()

                         .WithSql(
                g.sqlserver.Select <Edi>().ToSql(a => new { a.Id }, FieldAliasOptions.AsProperty) +
                " UNION ALL " +
                g.sqlserver.Select <Edi>().ToSql(a => new { a.Id }, FieldAliasOptions.AsProperty))

                         .Page(1, 10).ToSql("Id");

            var sqlextMax1 = g.sqlserver.Select <EdiItem>()
                             .GroupBy(a => a.Id)
                             .ToSql(a => new
            {
                Id     = a.Key,
                EdiId1 = SqlExt.Max(a.Key).Over().PartitionBy(new { a.Value.EdiId, a.Value.Id }).OrderByDescending(new { a.Value.EdiId, a.Value.Id }).ToValue(),
                EdiId2 = SqlExt.Max(a.Key).Over().PartitionBy(a.Value.EdiId).OrderByDescending(a.Value.Id).ToValue(),
                EdiId3 = SqlExt.Sum(a.Key).ToValue(),
                EdiId4 = a.Sum(a.Key)
            });

            var sqlextIsNull = g.sqlserver.Select <EdiItem>()
                               .ToSql(a => new
            {
                nvl = SqlExt.IsNull(a.EdiId, 0)
            });

            var sqlextGroupConcat = g.mysql.Select <Edi, EdiItem>()
                                    .InnerJoin((a, b) => b.Id == a.Id)
                                    .ToSql((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id,
                case1 = SqlExt.Case()
                        .When(a.Id == 1, 10)
                        .When(a.Id == 2, 11)
                        .When(a.Id == 3, 12)
                        .When(a.Id == 4, 13)
                        .When(a.Id == 5, SqlExt.Case().When(b.Id == 1, 10000).Else(999).End())
                        .End(),
                groupct1 = SqlExt.GroupConcat(a.Id).Distinct().OrderBy(b.EdiId).Separator("_").ToValue(),
                testb1   = b == null ? 1 : 0,
                testb2   = b != null ? 1 : 0,
            });
            var sqlextGroupConcatToList = g.mysql.Select <Edi, EdiItem>()
                                          .InnerJoin((a, b) => b.Id == a.Id)
                                          .ToList((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id,
                case1 = SqlExt.Case()
                        .When(a.Id == 1, 10)
                        .When(a.Id == 2, 11)
                        .When(a.Id == 3, 12)
                        .When(a.Id == 4, 13)
                        .When(a.Id == 5, SqlExt.Case().When(b.Id == 1, 10000).Else(999).End())
                        .End(),
                groupct1 = SqlExt.GroupConcat(a.Id).Distinct().OrderBy(b.EdiId).Separator("_").ToValue(),
                testb1   = b == null ? 1 : 0,
                testb2   = b != null ? 1 : 0,
            });

            var sqlextCase = g.sqlserver.Select <Edi, EdiItem>()
                             .InnerJoin((a, b) => b.Id == a.Id)
                             .ToSql((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id,
                case1 = SqlExt.Case()
                        .When(a.Id == 1, 10)
                        .When(a.Id == 2, 11)
                        .When(a.Id == 3, 12)
                        .When(a.Id == 4, 13)
                        .When(a.Id == 5, SqlExt.Case().When(b.Id == 1, 10000).Else(999).End())
                        .End(),
                over1 = SqlExt.Rank().Over().OrderBy(a.Id).OrderByDescending(b.EdiId).ToValue(),
            });
            var sqlextCaseToList = g.sqlserver.Select <Edi, EdiItem>()
                                   .InnerJoin((a, b) => b.Id == a.Id)
                                   .ToList((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id,
                case1 = SqlExt.Case()
                        .When(a.Id == 1, 10)
                        .When(a.Id == 2, 11)
                        .When(a.Id == 3, 12)
                        .When(a.Id == 4, 13)
                        .When(a.Id == 5, SqlExt.Case().When(b.Id == 1, 10000).Else(999).End())
                        .End(),
                over1 = SqlExt.Rank().Over().OrderBy(a.Id).OrderByDescending(b.EdiId).ToValue(),
            });

            var sqlextCaseGroupBy1 = g.sqlserver.Select <Edi, EdiItem>()
                                     .InnerJoin((a, b) => b.Id == a.Id)
                                     .GroupBy((a, b) => new { aid = a.Id, bid = b.Id })
                                     .ToDictionary(a => new
            {
                sum    = a.Sum(a.Value.Item2.EdiId),
                testb1 = a.Value.Item2 == null ? 1 : 0,
                testb2 = a.Value.Item2 != null ? 1 : 0,
            });

            var sqlextCaseGroupBy2 = g.sqlserver.Select <Edi, EdiItem>()
                                     .InnerJoin((a, b) => b.Id == a.Id)
                                     .GroupBy((a, b) => new { aid = a.Id, bid = b.Id })
                                     .ToList(a => new
            {
                a.Key, sum = a.Sum(a.Value.Item2.EdiId),
                testb1     = a.Value.Item2 == null ? 1 : 0,
                testb2     = a.Value.Item2 != null ? 1 : 0,
            });


            var sqlextOver = g.sqlserver.Select <Edi, EdiItem>()
                             .InnerJoin((a, b) => b.Id == a.Id)
                             .ToSql((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id,
                over1 = SqlExt.Rank().Over().OrderBy(a.Id).OrderByDescending(b.EdiId).ToValue()
            });
            var sqlextOverToList = g.sqlserver.Select <Edi, EdiItem>()
                                   .InnerJoin((a, b) => b.Id == a.Id)
                                   .ToList((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id,
                over1 = SqlExt.Rank().Over().OrderBy(a.Id).OrderByDescending(b.EdiId).ToValue()
            });

            var tttrule = 8;
            var tttid   = new long[] { 18, 19, 4017 };

            g.sqlserver.Update <Author123>().Set(it => it.SongId == (short)(it.SongId & ~tttrule)).Where(it => (it.SongId & tttrule) == tttrule && !tttid.Contains(it.Id)).ExecuteAffrows();

            g.sqlite.Delete <Song123>().Where("1=1").ExecuteAffrows();
            g.sqlite.Delete <Author123>().Where("1=1").ExecuteAffrows();
            g.sqlite.Insert(new Song123(1)).ExecuteAffrows();
            g.sqlite.Insert(new Author123(11, 1)).ExecuteAffrows();
            var song = g.sqlite.Select <Song123>()
                       .From <Author123>((a, b) => a.InnerJoin(a1 => a1.Id == b.SongId))
                       .First((a, b) => a); // throw error

            Console.WriteLine(song == null);

            g.sqlite.Select <Edi>().ToList();

            var itemId2 = 2;
            var itemId  = 1;
            var edi     = g.sqlite.Select <Edi>()
                          .Where(a => a.Id == itemId2 && g.sqlite.Select <EdiItem>().Where(b => b.Id == itemId).Any())
                          .First(a => a); //#231

            var lksdjkg1 = g.sqlite.Select <Edi>()
                           .AsQueryable().Where(a => a.Id > 0).Where(a => a.Id == 1).ToList();

            var lksdjkg11 = g.sqlite.Select <Edi>()
                            .AsQueryable().Where(a => a.Id > 0).Where(a => a.Id == 1).Any();

            var lksdjkg2 = g.sqlite.Select <Edi>()
                           .AsQueryable().Where(a => a.Id > 0).First();

            var lksdjkg3 = g.sqlite.Select <Edi>()
                           .AsQueryable().Where(a => a.Id > 0).FirstOrDefault();


            var sql222efe = g.sqlite.Select <Edi, EdiItem>()
                            .InnerJoin((a, b) => b.Id == g.sqlite.Select <EdiItem>().As("c").Where(c => c.EdiId == a.Id).OrderBy(c => c.Id).ToOne(c => c.Id))
                            .ToSql((a, b) => new
            {
                Id    = a.Id,
                EdiId = b.Id
            });

            var subSyetemId = "xxx";
            var list        = g.sqlite.Select <Menu, SubSystem>()
                              .LeftJoin((a, b) => a.SubNameID == b.Id)
                              .WhereIf(!string.IsNullOrEmpty(subSyetemId), (a, s) => a.SubNameID == subSyetemId)
                              .ToList((a, s) => new Menu
            {
                ID           = a.ID,
                SystemName   = s.Name,
                SubNameID    = s.Id,
                CreateTime   = a.CreateTime,
                Description  = a.Description,
                EnName       = a.EnName,
                Name         = a.Name,
                OperationIds = a.OperationIds,
                Parent       = a.Parent,
                ParentID     = a.ParentID,
                Url          = a.Url,
                UserID       = a.UserID
            });



            var context = new TestDbContext(g.sqlite);

            var sql = context.Songs
                      .Where(a =>
                             context.Authors
                             //.Select  //加上这句就不报错,不加上报 variable 'a' of type 'Song' referenced from scope '', but it is not defined
                             .Where(b => b.SongId == a.Id)
                             .Any())
                      .ToSql(a => a.Name);

            sql = context.Songs
                  .Where(a =>
                         context.Authors
                         .Select //加上这句就不报错,不加上报 variable 'a' of type 'Song' referenced from scope '', but it is not defined
                         .Where(b => b.SongId == a.Id)
                         .Any())
                  .ToSql(a => a.Name);

            //using (var conn = new SqlConnection("Data Source=.;Integrated Security=True;Initial Catalog=webchat-abc;Pooling=true;Max Pool Size=13"))
            //{
            //    conn.Open();
            //    conn.Close();
            //}

            //using (var fsql = new FreeSql.FreeSqlBuilder()
            //    .UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=webchat-abc;Pooling=true;Max Pool Size=13")
            //    .UseAutoSyncStructure(true)
            //    //.UseGenerateCommandParameterWithLambda(true)
            //    .UseMonitorCommand(
            //        cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
            //        //, (cmd, traceLog) => Console.WriteLine(traceLog)
            //        )
            //    .UseLazyLoading(true)
            //    .Build())
            //{
            //    fsql.Select<ut3_t1>().ToList();
            //}

            //var testByte = new TestByte { pic = File.ReadAllBytes(@"C:\Users\28810\Desktop\71500003-0ad69400-289e-11ea-85cb-36a54f52ebc0.png") };
            //var sql = g.sqlserver.Insert(testByte).NoneParameter().ToSql();
            //g.sqlserver.Insert(testByte).NoneParameter().ExecuteAffrows();

            //var getTestByte = g.sqlserver.Select<TestByte>(testByte).First();

            //File.WriteAllBytes(@"C:\Users\28810\Desktop\71500003-0ad69400-289e-11ea-85cb-36a54f52ebc0_write.png", getTestByte.pic);

            var ib = new IdleBus <IFreeSql>(TimeSpan.FromMinutes(10));

            ib.Notice += (_, e2) => Trace.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] 线程{Thread.CurrentThread.ManagedThreadId}:{e2.Log}");

            ib.Register("db1", () => new FreeSql.FreeSqlBuilder()
                        .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=3")
                        .UseAutoSyncStructure(true)
                        .UseGenerateCommandParameterWithLambda(true)
                        .UseMonitorCommand(cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText))
                        .UseLazyLoading(true)
                        .Build());
            ib.Register("db2", () => new FreeSql.FreeSqlBuilder()
                        .UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=3")
                        .UseAutoSyncStructure(true)
                        .UseGenerateCommandParameterWithLambda(true)
                        .UseLazyLoading(true)
                        .UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
                        .UseMonitorCommand(cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText))
                        .Build());
            ib.Register("db3", () => new FreeSql.FreeSqlBuilder()
                        .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=3")
                        .UseAutoSyncStructure(true)
                        .UseGenerateCommandParameterWithLambda(true)
                        .UseLazyLoading(true)
                        .UseMonitorCommand(cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText))
                        .Build());
            //...注入很多个

            var fsql       = ib.Get("db1"); //使用的时候用 Get 方法,不要存其引用关系
            var sqlparamId = 100;

            fsql.Select <ut3_t1>().Limit(10).Where(a => a.id == sqlparamId).ToList();

            fsql = ib.Get("db2");
            fsql.Select <ut3_t1>().Limit(10).Where(a => a.id == sqlparamId).ToList();

            fsql = ib.Get("db3");
            fsql.Select <ut3_t1>().Limit(10).Where(a => a.id == sqlparamId).ToList();

            fsql = g.sqlserver;
            fsql.Insert <OrderMain>(new OrderMain {
                OrderNo = "1001", OrderTime = new DateTime(2019, 12, 01)
            }).ExecuteAffrows();
            fsql.Insert <OrderDetail>(new OrderDetail {
                OrderNo = "1001", ItemNo = "I001", Qty = 1
            }).ExecuteAffrows();
            fsql.Insert <OrderDetail>(new OrderDetail {
                OrderNo = "1001", ItemNo = "I002", Qty = 1
            }).ExecuteAffrows();
            fsql.Insert <OrderDetail>(new OrderDetail {
                OrderNo = "1001", ItemNo = "I003", Qty = 1
            }).ExecuteAffrows();
            fsql.Insert <OrderMain>(new OrderMain {
                OrderNo = "1002", OrderTime = new DateTime(2019, 12, 02)
            }).ExecuteAffrows();
            fsql.Insert <OrderDetail>(new OrderDetail {
                OrderNo = "1002", ItemNo = "I011", Qty = 1
            }).ExecuteAffrows();
            fsql.Insert <OrderDetail>(new OrderDetail {
                OrderNo = "1002", ItemNo = "I012", Qty = 1
            }).ExecuteAffrows();
            fsql.Insert <OrderDetail>(new OrderDetail {
                OrderNo = "1002", ItemNo = "I013", Qty = 1
            }).ExecuteAffrows();
            fsql.Ado.Query <object>("select * from orderdetail left join ordermain on orderdetail.orderno=ordermain.orderno where ordermain.orderno='1001'");


            g.oracle.Delete <SendInfo>().Where("1=1").ExecuteAffrows();
            g.oracle.Insert(new[]
            {
                new SendInfo {
                    Code = "001", Binary = Encoding.UTF8.GetBytes("我是中国人")
                },
                new SendInfo {
                    Code = "002", Binary = Encoding.UTF8.GetBytes("我是地球人")
                },
                new SendInfo {
                    Code = "003", Binary = Encoding.UTF8.GetBytes("我是.net")
                },
                new SendInfo {
                    Code = "004", Binary = Encoding.UTF8.GetBytes("我是freesql")
                },
                new SendInfo {
                    Code = "005", Binary = Encoding.UTF8.GetBytes("我是freesql233")
                },
            })
            .NoneParameter()
            .BatchOptions(3, 200)
            .BatchProgress(a => Trace.WriteLine($"{a.Current}/{a.Total}"))
            .ExecuteAffrows();

            var slslsl = g.oracle.Select <SendInfo>().ToList();

            var slsls1Ids = slslsl.Select(a => a.ID).ToArray();
            var slslss2   = g.oracle.Select <SendInfo>().Where(a => slsls1Ids.Contains(a.ID)).ToList();

            var mt_codeId = Guid.Parse("2f48c5ca-7257-43c8-9ee2-0e16fa990253");

            Assert.Equal(1, g.oracle.Insert(new SendInfo {
                ID = mt_codeId, Code = "mt_code", Binary = Encoding.UTF8.GetBytes("我是mt_code")
            })
                         .ExecuteAffrows());
            var mt_code = g.oracle.Select <SendInfo>().Where(a => a.ID == mt_codeId).First();

            Assert.NotNull(mt_code);
            Assert.Equal(mt_codeId, mt_code.ID);
            Assert.Equal("mt_code", mt_code.Code);

            mt_code = g.oracle.Select <SendInfo>().Where(a => a.ID == Guid.Parse("2f48c5ca725743c89ee20e16fa990253".ToUpper())).First();
            Assert.NotNull(mt_code);
            Assert.Equal(mt_codeId, mt_code.ID);
            Assert.Equal("mt_code", mt_code.Code);

            mt_codeId = Guid.Parse("2f48c5ca-7257-43c8-9ee2-0e16fa990251");
            Assert.Equal(1, g.oracle.Insert(new SendInfo {
                ID = mt_codeId, Code = "mt_code2", Binary = Encoding.UTF8.GetBytes("我是mt_code2")
            })
                         .NoneParameter()
                         .ExecuteAffrows());
            mt_code = g.oracle.Select <SendInfo>().Where(a => a.ID == mt_codeId).First();
            Assert.NotNull(mt_code);
            Assert.Equal(mt_codeId, mt_code.ID);
            Assert.Equal("mt_code2", mt_code.Code);

            mt_code = g.oracle.Select <SendInfo>().Where(a => a.ID == Guid.Parse("2f48c5ca725743c89ee20e16fa990251".ToUpper())).First();
            Assert.NotNull(mt_code);
            Assert.Equal(mt_codeId, mt_code.ID);
            Assert.Equal("mt_code2", mt_code.Code);

            var id = g.oracle.Insert(new TestORC12()).ExecuteIdentity();
        }
Exemple #51
0
 public OrderSummaryService(TestDbContext testDB)
 {
     _testDB = testDB;
 }
Exemple #52
0
        public IntKeyedRepositoryTest()
        {
            DbOptions = new DbContextOptionsBuilder <TestDbContext>().UseInMemoryDatabase(databaseName: "Int").Options;

            _db = new TestDbContext(DbOptions);
        }
 public ProductsController(TestDbContext _db)
 {
     db = _db;
 }
 public EfCoreDbSetTests()
 {
     _dbInitializer   = new TestDbContextInitializer();
     _dbContext       = _dbInitializer.GetTestDbContext();
     _efCoreDbContext = new EfCoreDbContext <TestDbContext>(_dbContext);
 }
Exemple #55
0
 public Repository(TestDbContext dbContext) : base(dbContext)
 {
     this.dbContext = dbContext;
 }
Exemple #56
0
 public RegionRepository(TestDbContext context)
 {
     _context = context;
 }
Exemple #57
0
 public static TestDbContext CreateSimplyInit(this TestDbContext context, int count)
 {
     return(context.CreateTestUsers(count).CreateTestEmployees(count).CreateTestModels(count));
 }
 public SourcingDefinitionRepo(TestDbContext context) : base(context)
 {
 }
Exemple #59
0
 public BlogRepository(TestDbContext dbContext) : base(dbContext)
 {
     DbContext = dbContext;
 }
 public TestAggregateRootRepository2(TestDbContext context) :
     base(context)
 {
 }