Exemplo n.º 1
0
        public void TablesInScopeHintTest(
            [IncludeDataSources(true, TestProvName.AllSqlServer)] string context)
        {
            using var db = GetDataContext(context);

            var q =
                (
                    from p in db.Parent
                    from c in db.Child
                    from c1 in db.Child.AsSqlServer().WithIndex("IX_ChildIndex")
                    where c.ParentID == p.ParentID && c1.ParentID == p.ParentID
                    select p
                )
                .TablesInScopeHint(SqlServerHints.Table.NoLock);

            q =
                (
                    from p in q
                    from c in db.Child
                    from p1 in db.Parent.TablesInScopeHint(SqlServerHints.Table.HoldLock)
                    where c.ParentID == p.ParentID && c.Parent !.ParentID > 0 && p1.ParentID == p.ParentID
                    select p
                )
                .TablesInScopeHint(SqlServerHints.Table.NoWait);

            q =
                from p in q
                from c in db.Child
                where c.ParentID == p.ParentID
                select p;

            _ = q.ToList();

            var test = LastQuery?.Replace("\r", "");

            Assert.That(test, Contains.Substring("[Parent] [p] WITH (NoLock)"));
            Assert.That(test, Contains.Substring("[Child] [c_1] WITH (NoLock)"));
            Assert.That(test, Contains.Substring("[Child] [c_2] WITH (NoWait)"));
            Assert.That(test, Contains.Substring("[Parent] [a_Parent] WITH (NoWait)"));
            Assert.That(test, Contains.Substring("[Child] [c1] WITH (Index(IX_ChildIndex), NoLock)"));
            Assert.That(test, Contains.Substring("[Parent] [p1] WITH (HoldLock)"));
            Assert.That(test, Contains.Substring("[Child] [c_3]\n"));
        }
Exemplo n.º 2
0
        public void TablesInScopeHintTest([IncludeDataSources(true, ProviderName.SqlCe)] string context)
        {
            using var db = GetDataContext(context);

            var q =
                (
                    from p in db.Person.TableHint(SqlCeHints.Table.Index, "PK_Person")
                    from c in db.Child
                    where c.ParentID == p.ID
                    select p
                )
                .TablesInScopeHint(SqlCeHints.Table.NoLock);

            q =
                (
                    from p in q
                    from c in db.Child
                    from p1 in db.Parent.TablesInScopeHint(SqlCeHints.Table.HoldLock)
                    where c.ParentID == p.ID && c.Parent !.ParentID > 0 && p1.ParentID == p.ID
                    select p
                )
                .TablesInScopeHint(SqlCeHints.Table.PagLock);

            q =
                from p in q
                from c in db.Child
                where c.ParentID == p.ID
                select p;

            _ = q.ToList();

            var test = LastQuery?.Replace("\r", "");

            Assert.That(test, Contains.Substring("[Person] [p] WITH (Index(PK_Person), NoLock)"));
            Assert.That(test, Contains.Substring("[Child] [c_1] WITH (NoLock)"));
            Assert.That(test, Contains.Substring("[Parent] [p1] WITH (HoldLock)"));
            Assert.That(test, Contains.Substring("[Child] [c_2] WITH (PagLock)"));
            Assert.That(test, Contains.Substring("[Parent] [a_Parent] WITH (PagLock)"));
        }