当前位置: 首页>>代码示例>>C#>>正文


C# SqlLogSpy类代码示例

本文整理汇总了C#中SqlLogSpy的典型用法代码示例。如果您正苦于以下问题:C# SqlLogSpy类的具体用法?C# SqlLogSpy怎么用?C# SqlLogSpy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SqlLogSpy类属于命名空间,在下文中一共展示了SqlLogSpy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PropertyRefWithCompositeIdUpdateTest

        public void PropertyRefWithCompositeIdUpdateTest()
        {
            using (var spy = new SqlLogSpy())
            using (var session = OpenSession())
            using (session.BeginTransaction())
            {

                var direction1 = new Direction { Id1 = 1, Id2 = 1, GUID = Guid.NewGuid() };
                session.Save(direction1);
                
                var direction2 = new Direction { Id1 = 2, Id2 = 2, GUID = Guid.NewGuid() };
                session.Save(direction2);
                
                session.Flush();

                var directionReferrer = new DirectionReferrer
                                             {
                                                 GUID = Guid.NewGuid(),
                                                 Direction = direction1, 
                                             };

                session.Save(directionReferrer);

                directionReferrer.Direction = direction2;

                session.Update(directionReferrer);

                session.Flush();

                Console.WriteLine(spy.ToString());
                Assert.That(true);
            }
        }
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:33,代码来源:Fixture.cs

示例2: Test

		public void Test()
		{
			int a_id;
			using(ISession s = OpenSession())
			using(ITransaction tx = s.BeginTransaction())
			{
				// Create an A and save it
				ClassA a = new ClassA();
				a.Name = "a1";
				s.Save(a);

				// Create a B and save it
				ClassB b = new ClassB();
				b.Id = new ClassBId("bbb", a);
				b.SomeProp = "Some property";
				s.Save(b);

				// Create a C and save it
				ClassC c = new ClassC();
				c.B = b;
				s.Save(c);

				tx.Commit();

				a_id = a.Id;
			}

			// Clear the cache
			sessions.Evict(typeof(ClassA));
			sessions.Evict(typeof(ClassB));
			sessions.Evict(typeof(ClassC));
			
			using(ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				// Load a so we can use it to load b
				ClassA a = s.Get<ClassA>(a_id);

				// Load b so b will be in cache
				ClassB b = s.Get<ClassB>(new ClassBId("bbb", a));

				tx.Commit();
			}
			
			using(ISession s = OpenSession())
			using(ITransaction tx = s.BeginTransaction())
			{
				using (SqlLogSpy sqlLogSpy = new SqlLogSpy())
				{
					IList<ClassC> c_list = s.CreateCriteria(typeof (ClassC)).List<ClassC>();
					// make sure we initialize B
					NHibernateUtil.Initialize(c_list[0].B);

					Assert.AreEqual(1, sqlLogSpy.Appender.GetEvents().Length,
					                "Only one SQL should have been issued");
				}

				tx.Commit();
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:60,代码来源:Fixture.cs

示例3: CanCombineSingleFutureValueWithEnumerableFutures

		public void CanCombineSingleFutureValueWithEnumerableFutures()
		{
			using (var s = sessions.OpenSession())
			{
				IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();

				var persons = s.CreateCriteria(typeof(Person))
					.SetMaxResults(10)
					.Future<Person>();

				var personCount = s.CreateCriteria(typeof(Person))
					.SetProjection(Projections.RowCount())
					.FutureValue<int>();

				using (var logSpy = new SqlLogSpy())
				{
					int count = personCount.Value;

					foreach (var person in persons)
					{

					}

					var events = logSpy.Appender.GetEvents();
					Assert.AreEqual(1, events.Length);
				}
			}
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:28,代码来源:FutureCriteriaFixture.cs

示例4: DeleteWithoutUpdateVersion

		public void DeleteWithoutUpdateVersion()
		{
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				s.Save(new ObjectA { Bs = new List<ObjectB> { new ObjectB(), new ObjectB() } });
				t.Commit();
			}

			using (var ls = new SqlLogSpy())
			{
				using (ISession s = OpenSession())
				using (ITransaction t = s.BeginTransaction())
				{
					var a = s.CreateCriteria<ObjectA>().UniqueResult<ObjectA>();
					s.Delete(a);
					t.Commit();
				}
				string wholeLog = ls.GetWholeLog();
				Assert.That(wholeLog, Is.Not.StringContaining("UPDATE ObjectA"));
				Assert.That(wholeLog, Is.StringContaining("UPDATE ObjectB"),"should create orphans");
			}

			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				s.CreateQuery("delete from ObjectB").ExecuteUpdate();
				s.CreateQuery("delete from ObjectA").ExecuteUpdate();
				t.Commit();
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:31,代码来源:Fixture.cs

示例5: TwoFuturesRunInTwoRoundTrips

        public void TwoFuturesRunInTwoRoundTrips()
        {
            using (var s = sessions.OpenSession())
            {
				IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();

                using (var logSpy = new SqlLogSpy())
                {
                    var persons10 = s.CreateQuery("from Person")
                        .SetMaxResults(10)
                        .Future<Person>();

                    foreach (var person in persons10) { } // fire first future round-trip

                    var persons5 = s.CreateQuery("from Person")
                        .SetMaxResults(5)
                        .Future<int>();

                    foreach (var person in persons5) { } // fire second future round-trip

                    var events = logSpy.Appender.GetEvents();
                    Assert.AreEqual(2, events.Length);
                }
            }
        }
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:25,代码来源:FutureQueryFixture.cs

示例6: WhenPersistShouldNotFetchUninitializedCollection

		public void WhenPersistShouldNotFetchUninitializedCollection()
		{
			var companyId = CreateScenario();

			//Now in a second transaction i remove the address and persist Company: for a cascade option the Address will be removed
			using (var sl = new SqlLogSpy())
			{
				using (ISession session = sessions.OpenSession())
				{
					using (ITransaction tx = session.BeginTransaction())
					{
						var company = session.Get<Company>(companyId);
						company.Addresses.Count().Should().Be.EqualTo(1);
						company.RemoveAddress(company.Addresses.First()).Should().Be.EqualTo(true);

						//now this company will be saved and deleting the address.
						//BUT it should not try to load the BanckAccound collection!
						session.Persist(company);
						tx.Commit();
					}
				}
				var wholeMessage = sl.GetWholeLog();
				wholeMessage.Should().Not.Contain("BankAccount");
			}

			Cleanup(companyId);
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:27,代码来源:Fixture.cs

示例7: CanUseFutureCriteria

		public void CanUseFutureCriteria()
		{
			using (var s = sessions.OpenSession())
			{
				IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();

				var persons10 = s.QueryOver<Person>()
					.Take(10)
					.Future();
				var persons5 = s.QueryOver<Person>()
					.Select(p => p.Id)
					.Take(5)
					.Future<int>();

				using (var logSpy = new SqlLogSpy())
				{
					int actualPersons5Count = 0;
					foreach (var person in persons5)
						actualPersons5Count++;

					int actualPersons10Count = 0;
					foreach (var person in persons10)
						actualPersons10Count++;

					var events = logSpy.Appender.GetEvents();
					Assert.AreEqual(1, events.Length);

					Assert.That(actualPersons5Count, Is.EqualTo(1));
					Assert.That(actualPersons10Count, Is.EqualTo(1));
				}
			}
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:32,代码来源:FutureQueryOverFixture.cs

示例8: CanCombineSingleFutureValueWithEnumerableFutures

        public void CanCombineSingleFutureValueWithEnumerableFutures()
        {
            using (var s = sessions.OpenSession())
            {
				IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();

                var persons = s.CreateQuery("from Person")
                    .SetMaxResults(10)
                    .Future<Person>();

                var personCount = s.CreateQuery("select count(*) from Person")
                    .FutureValue<long>();

                using (var logSpy = new SqlLogSpy())
                {
                    long count = personCount.Value;

                    foreach (var person in persons)
                    {
                    }

                    var events = logSpy.Appender.GetEvents();
                    Assert.AreEqual(1, events.Length);
                }
            }
        }
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:26,代码来源:FutureQueryFixture.cs

示例9: Loking

		public void Loking()
		{
			object savedId;
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				A a = new A("hunabKu");
				savedId = s.Save(a);
				t.Commit();
			}

			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				A a = s.Get<A>(savedId);
				using (SqlLogSpy sqlLogSpy = new SqlLogSpy())
				{
					s.Lock(a, LockMode.Upgrade);
					string sql = sqlLogSpy.Appender.GetEvents()[0].RenderedMessage;
					Assert.Less(0, sql.IndexOf("with (updlock"));
				}
				t.Commit();
			}

			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				s.Delete("from A");
				t.Commit();
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:31,代码来源:Fixture.cs

示例10: CanOverrideStringEnumGetValue

		public void CanOverrideStringEnumGetValue()
		{
		    string paramPrefix = ((DriverBase) Sfi.ConnectionProvider.Driver).NamedPrefix;
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				using (SqlLogSpy ls = new SqlLogSpy())
				{
					Person person = new Person() { Sex = Sex.Male };
					s.Save(person);

					string log = ls.GetWholeLog();
					Assert.IsTrue(log.Contains(paramPrefix + "p0 = 'M'"));
				}

				using (SqlLogSpy ls = new SqlLogSpy())
				{
					Person person =
						s.CreateQuery("from Person p where p.Sex = :personSex")
							.SetParameter("personSex", Sex.Female)
							.UniqueResult<Person>();

					Assert.That(person, Is.Null);

					string log = ls.GetWholeLog();
					Assert.IsTrue(log.Contains(paramPrefix + "p0 = 'F'"));
				}

				tx.Rollback();
			}
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:31,代码来源:Fixture.cs

示例11: Bug

		public void Bug()
		{
			if((Dialect is SQLiteDialect)==false)
				Assert.Ignore("NH-1347 is sqlite specific");

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.Save(new A("1"));
				s.Save(new A("2"));
				s.Save(new A("3"));
				tx.Commit();
			}

			using(SqlLogSpy spy = new SqlLogSpy())
			using (ISession s = OpenSession())
			{
				A a = s.CreateCriteria(typeof (A))
					.AddOrder(Order.Asc("Name"))
					.SetMaxResults(1)
					.UniqueResult<A>();
				Assert.AreEqual("1", a.Name);
				Assert.IsTrue(
					spy.Appender.GetEvents()[0].MessageObject.ToString().Contains("limit")
					);
			}

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.Delete("from A");
				tx.Commit();
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:34,代码来源:Fixture.cs

示例12: CanUseFutureQuery

        public void CanUseFutureQuery()
        {
            using (var s = sessions.OpenSession())
            {
				IgnoreThisTestIfMultipleQueriesArentSupportedByDriver();

                var persons10 = s.CreateQuery("from Person")
                    .SetMaxResults(10)
                    .Future<Person>();
                var persons5 = s.CreateQuery("from Person")
                    .SetMaxResults(5)
                    .Future<int>();

                using (var logSpy = new SqlLogSpy())
                {
                    foreach (var person in persons5)
                    {

                    }

                    foreach (var person in persons10)
                    {

                    }

                    var events = logSpy.Appender.GetEvents();
                    Assert.AreEqual(1, events.Length);
                }
            }
        }
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:30,代码来源:FutureQueryFixture.cs

示例13: ShouldNotRemoveLineBreaksFromSqlQueries

		public void ShouldNotRemoveLineBreaksFromSqlQueries()
		{
			using (var spy = new SqlLogSpy())
			using (var s = OpenSession())
			using (var t = s.BeginTransaction())
			{
				const string sql = @"
select Id
from Entity
where 1=1";
				var query = s.CreateSQLQuery(sql);
				Assert.DoesNotThrow(() => query.List());

				string renderedSql = spy.Appender.GetEvents()[0].RenderedMessage;

				Regex whitespaces = new Regex(@"\s+", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);

				Assert.AreEqual(
					string.Compare(
						whitespaces.Replace(sql, " ").Trim(),
						whitespaces.Replace(renderedSql, " ").Trim(),
						true
						),
					0
				);
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:27,代码来源:Fixture.cs

示例14: EqualsNullShouldBeOuterJoin

 public void EqualsNullShouldBeOuterJoin()
 {
     using (var sqlLog = new SqlLogSpy())
     using (var session = OpenSession())
     {
         session.Query<MyBO>().Where(b => b.BO1.BO2 == null).ToList();
         var log = sqlLog.GetWholeLog();
         Assert.AreEqual(1, CountOuterJoins(log));
         Assert.AreEqual(0, CountInnerJoins(log));
     }
 }
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:11,代码来源:InnerJoinFixture.cs

示例15: ComparisonToConstantShouldBeInnerJoin

 public void ComparisonToConstantShouldBeInnerJoin()
 {
     using (var sqlLog = new SqlLogSpy())
     using (var session = OpenSession())
     {
         session.Query<MyBO>().Where(b => b.BO1.I1 == 1).ToList();
         var log = sqlLog.GetWholeLog();
         Assert.AreEqual(0, CountOuterJoins(log));
         Assert.AreEqual(1, CountInnerJoins(log));
     }
 }
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:11,代码来源:InnerJoinFixture.cs


注:本文中的SqlLogSpy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。