Example #1
0
        public static IEnumerable <T> DeleteObjectByObjectWhere <T>(this DataAccessObjectsQueryable <T> queryable, Expression <Func <T, bool> > condition)
            where T : DataAccessObject
        {
            if (queryable.ExtraCondition != null)
            {
                var parameter = Expression.Parameter(typeof(T), "value");

                var body = Expression.AndAlso(condition.Body, queryable.ExtraCondition);

                condition = Expression.Lambda <Func <T, bool> >(body, parameter);
            }

            foreach (T value in queryable.Where(condition))
            {
                value.Delete();

                yield return(value);
            }
        }
Example #2
0
        public static void DeleteWhere <T>(this DataAccessObjectsQueryable <T> queryable, Expression <Func <T, bool> > condition)
            where T : DataAccessObject
        {
            queryable.DataAccessModel.Flush();

            var transactionContext = queryable.DataAccessModel.AmbientTransactionManager.GetCurrentContext(true);

            using (var acquisition = transactionContext.AcquirePersistenceTransactionContext(queryable.DataAccessModel.GetCurrentSqlDatabaseContext()))
            {
                var expression = (Expression)Expression.Call(null, MethodCache <T> .DeleteMethod, Expression.Constant(queryable, typeof(DataAccessObjectsQueryable <T>)), condition);

                expression = Evaluator.PartialEval(expression);
                expression = QueryBinder.Bind(queryable.DataAccessModel, expression, queryable.ElementType, queryable.ExtraCondition);
                expression = ObjectOperandComparisonExpander.Expand(expression);
                expression = SqlQueryProvider.Optimize(expression, transactionContext.SqlDatabaseContext.SqlDataTypeProvider.GetTypeForEnums());

                acquisition.SqlDatabaseCommandsContext.Delete((SqlDeleteExpression)expression);
            }
        }
Example #3
0
 public static IQueryable <R> SelectForUpdate <T, R>(this DataAccessObjectsQueryable <T> queryable, Expression <Func <T, R> > condition)
     where T : DataAccessObject
 {
     return(queryable.PersistenceQueryProvider.CreateQuery <R>(Expression.Call(null, ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(T)), Expression.Constant(queryable), condition)));
 }