public void StaleObjectStateCheckWithEntityPersisterAndOptimisticLock()
		{
			Optimistic optimistic = new Optimistic();
			optimistic.String = "original string";

			try
			{
				using (ISession session = OpenSession())
				{
					session.Save(optimistic);
					session.Flush();

					using (ISession concurrentSession = OpenSession())
					{
						Optimistic sameOptimistic = (Optimistic) concurrentSession.Get(typeof(Optimistic), optimistic.Id);
						sameOptimistic.String = "another string";
						concurrentSession.Flush();
					}

					optimistic.String = "new string";
					Assert.Throws<StaleObjectStateException>(() => session.Flush());
				}
			}
			finally
			{
				using (ISession session = OpenSession())
				{
					session.Delete("from Optimistic");
					session.Flush();
				}
			}
		}
コード例 #2
0
		public void DeleteOptimistic()
		{
			using (ISession s = OpenSession())
			{
				Optimistic op = new Optimistic();
				op.Bag = new List<string> {"xyz"};

				s.Save(op);
			}

			using (ISession s = OpenSession())
			{
				s.Delete("from Optimistic");
				s.Flush();
			}
		}
		public void DeleteOptimistic()
		{
			using (ISession s = OpenSession())
			{
				Optimistic op = new Optimistic();
				op.Bag = new ArrayList();
				op.Bag.Add("xyz");

				s.Save(op);
			}

			using (ISession s = OpenSession())
			{
				s.Delete("from Optimistic");
				s.Flush();
			}
		}