public void ViewOnFilteredCollection()
        {
            AggregateTestCollection collection = new AggregateTestCollection();
            collection.Query.Load();
            Assert.AreEqual(30, collection.Count);
            collection.Filter = collection.AsQueryable().Where(f => f.LastName == "Doe");
            Assert.AreEqual(3, collection.Count);

            esEntityCollectionView<AggregateTest> view1 =
                new esEntityCollectionView<AggregateTest>(collection);
            Assert.AreEqual(30, view1.Count);
            Assert.AreEqual(3, collection.Count);
        }
		public void TestDateTime()
		{
            int testId = -1;
            AggregateTestCollection aggTestColl = new AggregateTestCollection();
            AggregateTest test = new AggregateTest();

            try
            {
                using (EntitySpaces.Interfaces.esTransactionScope scope =
                    new EntitySpaces.Interfaces.esTransactionScope())
                {
                    aggTestColl.Query.Load();
                    aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);
                    test = (AggregateTest)aggTestColl[0];
                    DateTime date = test.HireDate.Value;
                    Assert.AreEqual(Convert.ToDateTime("02/16/2000 05:59:31"), date);

                    test = new AggregateTest();
                    test.HireDate = Convert.ToDateTime("12/31/9999");
                    test.Save();
                    testId = test.Id.Value;

                    test = new AggregateTest();
                    Assert.IsTrue(test.LoadByPrimaryKey(testId));
                    Assert.AreEqual(Convert.ToDateTime("12/31/9999"), test.HireDate.Value);
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
            finally
            {
                // Clean up
                test = new AggregateTest();
                if (test.LoadByPrimaryKey(testId))
                {
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
		}
        public void TwoFilteredViewsOnFilteredCollection()
        {
            AggregateTestCollection collection = new AggregateTestCollection();
            collection.Query.Load();
            Assert.AreEqual(30, collection.Count);
            collection.Filter = collection.AsQueryable().Where(f => f.LastName == "Doe");
            Assert.AreEqual(3, collection.Count);

            esEntityCollectionView<AggregateTest> view1 =
                new esEntityCollectionView<AggregateTest>(collection);
            Assert.AreEqual(30, view1.Count);
            view1.Filter = view1.AsQueryable().Where(f => f.Age > 20);
            Assert.AreEqual(18, view1.Count);
            Assert.AreEqual(3, collection.Count);

            esEntityCollectionView<AggregateTest> view2 =
                new esEntityCollectionView<AggregateTest>(collection);
            Assert.AreEqual(30, view2.Count);
            view2.Filter = view2.AsQueryable().Where(f => f.FirstName == "John");
            Assert.AreEqual(2, view2.Count);
            Assert.AreEqual(18, view1.Count);
            Assert.AreEqual(3, collection.Count);
        }
        public void IterateSortedViewAndCollection()
        {
            AggregateTestCollection collection = new AggregateTestCollection();
            collection.Query.Load();
            collection.Filter = collection.AsQueryable().OrderBy(s => s.LastName);

            esEntityCollectionView<AggregateTest> view1 =
                new esEntityCollectionView<AggregateTest>(collection);
            view1.Filter = view1.AsQueryable().OrderByDescending(s => s.LastName);

            string prevName = collection[0].LastName;
            foreach (AggregateTest at in collection)
            {
                Assert.IsTrue(String.Compare(prevName, at.LastName) <= 0);
                prevName = at.LastName;
            }

            prevName = view1[0].LastName;
            foreach (AggregateTest at in view1)
            {
                Assert.IsTrue(String.Compare(prevName, at.LastName) >= 0);
                prevName = at.LastName;
            }
        }
		public void TestDateInSelect()
		{
			AggregateTestCollection collection = new AggregateTestCollection();
			collection.Query.Select(collection.Query.HireDate.Date());
            string lq = collection.Query.Parse();
			collection.Query.Load();
			Assert.AreEqual(30, collection.Count);
            collection.Filter = collection.AsQueryable().Where(f => f.HireDate != null && f.HireDate.Value.ToShortDateString() == "2/16/2000");
			Assert.AreEqual(1, collection.Count);
		}
		public void TestCoalesceInSelect()
		{
			AggregateTestCollection collection = new AggregateTestCollection();
			if (collection.es.Connection.ProviderMetadataKey != "esAccess")
			{
				collection.Query.Select(collection.Query.LastName.Coalesce("'x'"));
				collection.Query.Load();
				collection.Filter = collection.AsQueryable().Where(f => f.LastName == "x");
				Assert.AreEqual(6, collection.Count);
			}
			else
			{
				Assert.Ignore("Not supported.");
			}
		}
        public void FilteredDeleteAll()
        {
            using (esTransactionScope scope = new esTransactionScope())
            {
                AggregateTestCollection aggTestColl = new AggregateTestCollection();
                aggTestColl.LoadAll();
                Assert.AreEqual(30, aggTestColl.Count);
                aggTestColl.Filter = aggTestColl.AsQueryable().Where(f => f.LastName == "Doe");
                Assert.AreEqual(3, aggTestColl.Count);

                aggTestColl.MarkAllAsDeleted();

                aggTestColl.Filter = null;
                Assert.AreEqual(27, aggTestColl.Count);

                aggTestColl.Save();

                aggTestColl = new AggregateTestCollection();
                aggTestColl.LoadAll();
                Assert.AreEqual(27, aggTestColl.Count);
            }
        }