Exemplo n.º 1
0
        public void IQueryable_ShouldThrowUnsupportedExceptionIfTheyIncludeAFunctionInTheWhereClause()
        {
            using (var db = CreateSqlServerDB())
            {
                try
                {
                    db.SqlMode = SqlModes.Text;
                    db.BeginTransaction();

                    var existingOrders = db.Query <Order>().Where(o => o.ID > 0).ToList();
                    int count          = existingOrders.Count;
                    db.Delete <Order>(o => o.ID > 0);

                    Order order1 = new Order {
                        OrderName = "Test1"
                    };
                    db.Insert(order1);

                    // Bury the order within another object to ensure that the expression visitor can parse out the OrderName
                    var nestedPropertyObj = new NestedPropertyObject
                    {
                        Order = new Order {
                            OrderName = "Test1"
                        }
                    };

                    var order = db.Queryable <Order>()
                                .Where(o => o.OrderName == nestedPropertyObj.GetOrder().OrderName)
                                .FirstOrDefault();

                    Assert.IsNotNull(order);
                    Assert.AreEqual("Test1", order.OrderName);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    db.RollBack();
                }
            }
        }
Exemplo n.º 2
0
		public void IQueryable_ShouldThrowUnsupportedExceptionIfTheyIncludeAFunctionInTheWhereClause()
		{
			using (var db = CreateSqlServerDB())
			{
				try
				{
					db.SqlMode = SqlModes.Text;
					db.BeginTransaction();

					var existingOrders = db.Query<Order>().Where(o => o.ID > 0).ToList();
					int count = existingOrders.Count;
					db.Delete<Order>(o => o.ID > 0);

					Order order1 = new Order { OrderName = "Test1" };
					db.Insert(order1);

					// Bury the order within another object to ensure that the expression visitor can parse out the OrderName
					var nestedPropertyObj = new NestedPropertyObject
					{
						Order = new Order { OrderName = "Test1" }
					};

					var order = db.Queryable<Order>()
						.Where(o => o.OrderName == nestedPropertyObj.GetOrder().OrderName)
						.FirstOrDefault();

					Assert.IsNotNull(order);
					Assert.AreEqual("Test1", order.OrderName);
				}
				catch
				{
					throw;
				}
				finally
				{
					db.RollBack();
				}
			}
		}