public T GetEntity <T>(Expression <Func <T, bool> > predicate, IQueryStrategy queryStrategy, bool throwExceptionIfZeroOrManyFound) where T : class
        {
            Check.NotNull(predicate, "predicate");
            Check.NotNull(queryStrategy, "queryStrategy");

            return(QueryRepository.GetEntity <T>(predicate, queryStrategy, throwExceptionIfZeroOrManyFound));
        }
Beispiel #2
0
        //[Obsolete("experimental")]
        public static TElement FirstOrDefault <TElement>(this IQueryStrategy <TElement> source)
        {
            // will it work for jvm?
            var t = new StackTrace(0, true);
            var s = Stopwatch.StartNew();

            Console.WriteLine();

            // X:\jsc.svn\examples\javascript\linq\test\TestSelectAndSubSelect\TestSelectAndSubSelect\ApplicationWebService.cs
            // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectFirstOrDefault\TestSelectFirstOrDefault\ApplicationWebService.cs
            // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectMember\TestSelectMember\ApplicationWebService.cs



            var value = source.Take(1).AsGenericEnumerable().FirstOrDefault();

            var caller = t.GetFrame(1);

            Console.WriteLine(
                Process.GetCurrentProcess().Id.ToString("x4") + ":"
                + Thread.CurrentThread.ManagedThreadId.ToString("x4")
                + " FirstOrDefault " + new { s.ElapsedMilliseconds, Debugger.IsAttached, caller = caller.ToString() });

            return(value);
        }
        public T GetEntity <T>(IQueryStrategy queryStrategy, IQueryStrategy queryStrategy2, bool throwExceptionIfZeroOrManyFound) where T : class
        {
            Check.NotNull(queryStrategy, "queryStrategy");
            Check.NotNull(queryStrategy2, "queryStrategy2");

            return(GetEntity <T>(new AggregateQueryStrategy(queryStrategy, queryStrategy2), throwExceptionIfZeroOrManyFound));
        }
Beispiel #4
0
        public static Task <long> CountAsync <TElement>(this IQueryStrategy <TElement> source, IDbConnection cc)
        {
            // in CLR and in browser this would work.

            var z = new TaskCompletionSource <long>();


            // Error    178 'ScriptCoreLib.Query.Experimental.QueryExpressionBuilder.SQLWriter<TElement>' does not contain a definition for 'CountReference'    X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\Query\Experimental\QueryExpressionBuilderAsync.IDbConnection.Count.cs   47  112 ScriptCoreLib.Async

            var c = (DbCommand)source.GetScalarCommand(cc, Operand: QueryExpressionBuilder.xReferencesOfLong.CountReference.Method);

            // http://referencesource.microsoft.com/#System.Data/data/System/Data/Common/DBCommand.cs
            var xDbCommand = c as DbCommand;

            if (xDbCommand != null)
            {
                var n = xDbCommand.ExecuteScalarAsync();

                // X:\jsc.svn\examples\javascript\LINQ\LINQWebCamAvatars\LINQWebCamAvatars\Application.cs

                n.ContinueWithResult(
                    zz =>
                {
                    z.SetResult((long)zz);
                }
                    );

                return(z.Task);
            }



            throw new NotSupportedException();
        }
        public async Task <T> GetEntityAsync <T>(IQueryStrategy queryStrategy, IQueryStrategy queryStrategy2, bool throwExceptionIfZeroOrManyFound) where T : class
        {
            Check.NotNull(queryStrategy, "queryStrategy");
            Check.NotNull(queryStrategy2, "queryStrategy2");

            return(await Task.Run(() => QueryRepository.GetEntity <T>(queryStrategy, queryStrategy2, throwExceptionIfZeroOrManyFound)));
        }
        // used by
        // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\Query\Experimental\QueryExpressionBuilderAsync.SumAsync.cs
        // return DbCommand to provide Async versions of execute.
        public static DbCommand GetScalarCommand <TElement>(
            this IQueryStrategy <TElement> source,
            IDbConnection cc,

            MethodInfo Operand
            )
        {
            //Console.WriteLine("enter GetScalarCommand " + new { cc });

            var nsource = new xScalar {
                source = source, Operand = Operand
            };
            var Command = default(DbCommand);


            if (cc != null)
            {
                Command = (DbCommand)cc.CreateCommand();
            }
            else
            {
                // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestAndroidInsert\ApplicationWebService.cs

                Console.WriteLine("enter GetScalarCommand cc null ?");
            }

            var w = new SQLWriter <TElement>(nsource, new IQueryStrategy[] { nsource }, Command: Command);

            return(Command);
        }
        public T GetEntity <T>(IQueryStrategy queryStrategy, IQueryStrategy queryStrategy2, bool throwExceptionIfZeroOrManyFound) where T : class
        {
            Check.NotNull(queryStrategy, "queryStrategy");
            Check.NotNull(queryStrategy2, "queryStrategy2");

            return(QueryRepository.GetEntity <T>(queryStrategy, queryStrategy2, throwExceptionIfZeroOrManyFound));
        }
Beispiel #8
0
 // called by LINQ
 public static IQueryStrategy <TResult> Select <TSource, TResult>(this IQueryStrategy <TSource> source, Expression <Func <TSource, TResult> > selector)
 {
     return(new xSelect <TResult>
     {
         source = source,
         selector = selector
     });
 }
Beispiel #9
0
 // called by LINQ
 public static IQueryStrategy <TElement> Take <TElement>(this IQueryStrategy <TElement> source, int count)
 {
     return(new xTake <TElement>
     {
         source = source,
         count = count
     });
 }
        //[Obsolete("mutable")]
        public static IQueryStrategy <TElement> OrderBy <TElement, TKey>(this IQueryStrategy <TElement> source, Expression <Func <TElement, TKey> > keySelector)
        {
            MutableOrderBy(
                source, keySelector
                );

            return(source);
        }
        public static IQueryStrategy <TElement> ThenByDescending <TElement, TKey>(this IQueryStrategy <TElement> source, Expression <Func <TElement, TKey> > keySelector)
        {
            MutableOrderBy(
                source, keySelector, desc: true
                );

            return(source);
        }
        // convinience method
        public static void Delete <TElement>(this IQueryStrategy <TElement> source, Expression <Func <TElement, bool> > filter)
        {
            // could we also just ask for a key?
            // can we ask a TElement to have a key field for us? generic field constraint?

            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectMath\Program.cs
            source.Where(filter).Delete();
        }
Beispiel #13
0
        public static IQueryStrategy <TElement> Take <TElement>(this IQueryStrategy <TElement> source, long count)
        {
            MutableTake(
                source, count
                );

            return(source);
        }
        public EntitySearchRepositoryException(int rowsFound, string entityName, IQueryStrategy queryStrategy)
        {
            Check.NotEmpty(entityName, "entityName");
            Check.NotNull(queryStrategy, "parameters");

            QueryStrategy = queryStrategy;
            RowsFound = rowsFound;
            EntityName = entityName;
        }
 // delete all?
 public static void Delete <TElement>(this IQueryStrategy <TElement> source)
 {
     WithConnection(
         cc =>
     {
         Delete(source, cc);
     }
         );
 }
        public EntitySearchRepositoryException(int rowsFound, string entityName, IQueryStrategy queryStrategy)
        {
            Check.NotEmpty(entityName, "entityName");
            Check.NotNull(queryStrategy, "parameters");

            QueryStrategy = queryStrategy;
            RowsFound     = rowsFound;
            EntityName    = entityName;
        }
Beispiel #17
0
 public EntityQueryable(IQueryable source, Expression expression, IQueryStrategy queryStrategy)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     this._expression = expression;
     this._provider   = new EntityQueryProvider(source, queryStrategy);
 }
        public SimpleRepositoryQueryEvent(IQueryRepository repository, IQueryStrategy queryStrategy, object additionalQueryData, bool?throwExceptionIfZeroOrManyFound)
            : base(repository)
        {
            Check.NotNull(repository, "repository");
            Check.NotNull(queryStrategy, "queryStrategy");

            AdditionalQueryData             = additionalQueryData;
            QueryStrategy                   = queryStrategy;
            ThrowExceptionIfZeroOrManyFound = throwExceptionIfZeroOrManyFound;
        }
 public static CommandBuilderState AsCommandBuilder(IQueryStrategy Strategy)
 {
     // time to build the CommandText
     return(AsCommandBuilder(
                new CommandBuilderState
     {
         Strategy = Strategy,
     }
                ));
 }
        public SimpleRepositoryQueryEvent(IQueryRepository repository, IQueryStrategy queryStrategy, object additionalQueryData, bool? throwExceptionIfZeroOrManyFound)
            : base(repository)
        {
            Check.NotNull(repository, "repository");
            Check.NotNull(queryStrategy, "queryStrategy");

            AdditionalQueryData = additionalQueryData;
            QueryStrategy = queryStrategy;
            ThrowExceptionIfZeroOrManyFound = throwExceptionIfZeroOrManyFound;
        }
 //[Obsolete("mutable")]
 public static IQueryStrategy <TElement> OrderBy <TElement, TKey>(this IQueryStrategy <TElement> source, Expression <Func <TElement, TKey> > keySelector)
 {
     return(new xOrderBy <TElement>
     {
         source = source,
         keySelector = new[] { new xOrderBySelector {
                                   keySelector = keySelector, ascending = true
                               } }
     });
 }
        public T GetEntity <T>(Expression <Func <T, bool> > predicate, IQueryStrategy queryStrategy, IQueryStrategy queryStrategy2, bool throwExceptionIfZeroOrManyFound) where T : class
        {
            Check.NotNull(predicate, "predicate");
            Check.NotNull(queryStrategy, "queryStrategy");
            Check.NotNull(queryStrategy2, "queryStrategy2");

            return(GetEntity <T>(
                       new AggregateQueryStrategy(new ExpressionSpecificationQueryStrategy <T>(predicate), queryStrategy, queryStrategy2),
                       throwExceptionIfZeroOrManyFound));
        }
        public static double Sum <TElement>(this IQueryStrategy <TElement> Strategy, Expression <Func <TElement, double> > selector)
        {
            // http://stackoverflow.com/questions/3785995/sqlite-accumulator-sum-column-in-a-select-statement
            // http://www.tutorialspoint.com/sqlite/sqlite_useful_functions.htm
            //throw new NotImplementedException("sqlite does not have it yet");
            // http://sqlite.1065341.n5.nabble.com/SUM-and-NULL-values-td2257.html

            var body = ((MemberExpression)((LambdaExpression)selector).Body);

            // do we need to check our db schema or is reflection the schema for us?
            #region ColumnName
            var ColumnName = "";

            ColumnName = body.Member.Name;
            #endregion



            return(((Task <double>)Strategy.GetDescriptor().GetWithConnection()(
                        c =>
            {
                var state = QueryStrategyExtensions.AsCommandBuilder(Strategy);

                // override
                state.SelectCommand = "select sum(`" + ColumnName + "`) ";

                //var cmd = new SQLiteCommand(state.ToString(), c);
                var cmd = c.CreateCommand(state.ToString());

                foreach (var item in state.ApplyParameter)
                {
                    item(cmd);
                }

                var s = new TaskCompletionSource <double>();


                s.SetResult(
                    (double)cmd.ExecuteScalar()
                    );

                //var r = cmd.ExecuteReader();

                //if (r.NextResult())
                //{
                //    //ex = {"No current row"}
                //    s.SetResult(
                //        r.GetInt64(0)
                //    );
                //}

                return s.Task;
            }
                        )).Result);
        }
        public static TResult Min <TElement, TResult>(this IQueryStrategy <TElement> Strategy, Expression <Func <TElement, TResult> > selector)
        {
            // X:\jsc.svn\examples\javascript\LINQ\MinMaxAverageExperiment\MinMaxAverageExperiment\ApplicationWebService.cs

            return(((Task <TResult>)Strategy.GetDescriptor().GetWithConnection()(
                        c =>
            {
                // http://stackoverflow.com/questions/3785995/sqlite-accumulator-sum-column-in-a-select-statement
                // http://www.tutorialspoint.com/sqlite/sqlite_useful_functions.htm
                // http://sqlite.1065341.n5.nabble.com/SUM-and-NULL-values-td2257.html

                var body = ((MemberExpression)((LambdaExpression)selector).Body);

                // do we need to check our db schema or is reflection the schema for us?
                #region ColumnName
                var ColumnName = "";

                ColumnName = body.Member.Name;
                #endregion

                var state = QueryStrategyExtensions.AsCommandBuilder(Strategy);

                // override
                state.SelectCommand = "select min(`" + ColumnName + "`) ";

                //var cmd = new SQLiteCommand(state.ToString(), c);
                var cmd = c.CreateCommand(state.ToString());

                foreach (var item in state.ApplyParameter)
                {
                    item(cmd);
                }

                var s = new TaskCompletionSource <TResult>();

                // will it compile to java???
                s.SetResult(
                    (TResult)cmd.ExecuteScalar()
                    );

                //var r = cmd.ExecuteReader();

                //if (r.NextResult())
                //{
                //    //ex = {"No current row"}
                //    s.SetResult(
                //        r.GetInt64(0)
                //    );
                //}

                return s.Task;
            }
                        )).Result);
        }
        public LoadRepositoryQueryEvent(IQueryRepository repository, TEntity entity, object navigationProperty, IQueryStrategy queryStrategy)
            : base(repository)
        {
            Check.NotNull(repository, "repository");
            Check.NotNull(entity, "entity");
            Check.NotNull(navigationProperty, "navigationProperty");

            Entity             = entity;
            QueryStrategy      = queryStrategy;
            NavigationProperty = navigationProperty;
        }
        public static TElement FirstOrDefault <TElement>(this IQueryStrategy <TElement> source, IDbConnection cc)
        {
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs
            // make sure the reader will be closed

            // Additional information: Fatal error encountered during command execution.

            var a = source.Take(1).AsEnumerable(cc).ToArray();

            return(a.FirstOrDefault());
        }
 GroupBy <TSource, TKey, TElement>(this IQueryStrategy <TSource> source,
                                   Expression <Func <TSource, TKey> > keySelector,
                                   Expression <Func <TSource, TElement> > elementSelector
                                   )
 {
     return(new xGroupBy <IQueryStrategyGrouping <TKey, TElement> >
     {
         source = source,
         keySelector = keySelector,
         elementSelector = elementSelector
     });
 }
        public static IQueryStrategy <TElement> OrderByDescending <TElement, TKey>(this IQueryStrategy <TElement> source, Expression <Func <TElement, TKey> > keySelector)
        {
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestOrderByDescending\Program.cs

            return(new xOrderBy <TElement>
            {
                source = source,
                keySelector = new[] { new xOrderBySelector {
                                          keySelector = keySelector, ascending = false
                                      } }
            });
        }
        public static IQueryStrategy <TElement> Where <TElement>(this IQueryStrategy <TElement> source, Expression <Func <TElement, bool> > filter)
        {
            // which thread are we running on?
            // X:\jsc.svn\examples\javascript\appengine\AppEngineUserAgentLoggerWithXSLXAsset\AppEngineUserAgentLoggerWithXSLXAsset\ApplicationWebService.cs
            Console.WriteLine("enter Where");


            var xINestedQueryStrategy = source is INestedQueryStrategy;

            if (!xINestedQueryStrategy)
            {
                // lets mark it as nestable, this allows where to know how to aviod name clashes.
                // X:\jsc.svn\examples\javascript\linq\test\TestGroupByCountViaScalarWhere\TestGroupByCountViaScalarWhere\ApplicationWebService.cs
                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201406/20140607


                // first step being immputable for where clauses
                var that = new WhereQueryStrategy <TElement>
                {
                    source = source,
                    filter = filter,


                    InternalGetElementType =
                        delegate
                    {
                        return(source.GetElementType());
                    },

                    InternalGetDescriptor =
                        () =>
                    {
                        // inherit the connection/context from above
                        var StrategyDescriptor = source.GetDescriptor();

                        return(StrategyDescriptor);
                    }
                };

                MutableWhere(
                    that, filter
                    );

                return(that);
            }

            MutableWhere(
                source, filter
                );

            return(source);
        }
Beispiel #30
0
        GroupBy <TSource, TKey>(IQueryStrategy <TSource> source,
                                Expression <Func <TSource, TKey> > keySelector)
        {
            // e = qAUABi01lj2yX93nEIaSJw(zh4ABtC6ljmbrk8x5kK6iA(new ctor$Wh4ABhfpfj6IFLf_a4gLSZg(type$AAAAAAAAAAAAAAAAAAAAAA)), 'e');

            // ReferenceError: type$AAAAAAAAAAAAAAAAAAAAAA is not defined
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestWebOrderByThenGroupBy\Application.cs
            // jsc. need to do MakeArray?

            Expression <Func <TSource, TSource> > elementSelector = e => e;

            return(null);
        }
 public EntityQueryProvider(IQueryable source, IQueryStrategy queryStrategy)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (queryStrategy == null)
     {
         throw new ArgumentNullException("ordering");
     }
     this.queryStrategy = queryStrategy;
     this._source       = source;
 }
Beispiel #32
0
        // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\Experimental\QueryExpressionBuilder.IDbConnection.Count.cs
        // X:\jsc.svn\examples\javascript\Test\TestSQLiteConnection\TestSQLiteConnection\Application.cs
        // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\Experimental\QueryExpressionBuilder.IDbConnection.Insert.cs
        // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs

        // X:\jsc.svn\examples\javascript\LINQ\ClickCounter\ClickCounter\Application.cs
        public static Task <long> CountAsync <TElement>(this IQueryStrategy <TElement> source)
        {
            var z = new TaskCompletionSource <long>();

            // was it manually set?
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                CountAsync(source, cc).ContinueWithResult(z.SetResult);
            }
                );
            return(z.Task);
        }
 public static CommandBuilderState AsCommandBuilder(IQueryStrategy Strategy)
 {
     // time to build the CommandText
     return AsCommandBuilder(
         new CommandBuilderState
     {
         Strategy = Strategy,
     }
     );
 }
        // upper select needs us to proxy some fields
        public static void WriteExpressionAlias(
            this CommandBuilderState state,
            // either WhereCommand or SelectCommand
            // byref against locals will likely work better than fields 
            ref string s,
            Expression asExpression,

            IQueryStrategy that
        )
        {
            // asExpression = {nt => new <>f__AnonymousType5`1(AccountToID = nt.Last().t.OtherPartyIBAN)}
            // asExpression = {nt => nt.Last().t.OtherPartyIBAN}
            // asExpression = {nt => 2}

            #region LambdaExpression - upper selector
            var xLambdaExpression = asExpression as LambdaExpression;
            if (xLambdaExpression != null)
            {
                // look the join needs to proxy fields and the upper select isnt selecting scalar..

                // um. we do need to flatten it.

                //var xasNewExpression = xasLambdaExpression.Body as NewExpression;
                // 


                WriteExpressionAlias(
                    state,
                    ref s,
                    xLambdaExpression.Body,
                    that
                );

                return;
            }
            #endregion

            #region xConstantExpression
            var xConstantExpression = asExpression as ConstantExpression;
            if (xConstantExpression != null)
            {
                // lets not try to proxy the constant.
                // the upper select will render it itself
                return;
            }
            #endregion

            // +		asExpression	{nt.Last().t.OtherPartyIBAN}	System.Linq.Expressions.Expression {System.Linq.Expressions.FieldExpression}
            var xMemberExpression = asExpression as MemberExpression;
            if (xMemberExpression != null)
            {
                // scalar field selection?

                s += "\n" + QueryStrategyOfTRowExtensions.CommentLineNumber() + "\t"
                    // shall we look at 'that' and try to understand whats the name of the member?
                    + xMemberExpression.Member.Name + " as " + xMemberExpression.Member.Name;




                return;
            }

            Debugger.Break();

        }
        // are the extension methods the new instance methods?
        // shall we  start by string::IsNullOrEmpty ?
        // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectDatesThenCountSimilars\TestSelectDatesThenCountSimilars\ApplicationWebService.cs
        public static void WriteExpression(
            this CommandBuilderState state,
            // either WhereCommand or SelectCommand
            // byref against locals will likely work better than fields 
            ref string s,
            Expression asExpression,

            IQueryStrategy that
            )
        {
            // X:\jsc.svn\examples\javascript\linq\test\TestWhereIsNullOrEmpty\TestWhereIsNullOrEmpty\ApplicationWebService.cs
            // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\QueryStrategyOfTRowExtensions.Where.cs

            // where not(`path` is null or length(`path`) = 0)
            // asExpression = {Not(IsNullOrEmpty(x.path))}

            #region asBinaryExpression
            var asBinaryExpression = asExpression as BinaryExpression;
            if (asBinaryExpression != null)
            {
                s += "(";
                state.WriteExpression(ref s, asBinaryExpression.Left, that);


                #region ExpressionType
                if (asBinaryExpression.NodeType == ExpressionType.Equal)
                    s += "=";
                else if (asBinaryExpression.NodeType == ExpressionType.LessThan)
                    s += "<";
                else if (asBinaryExpression.NodeType == ExpressionType.LessThanOrEqual)
                    s += "<=";
                else if (asBinaryExpression.NodeType == ExpressionType.GreaterThan)
                    s += ">";
                else if (asBinaryExpression.NodeType == ExpressionType.GreaterThanOrEqual)
                    s += ">=";
                else if (asBinaryExpression.NodeType == ExpressionType.NotEqual)
                    s += "<>";
                else if (asBinaryExpression.NodeType == ExpressionType.OrElse)
                    s += " or ";
                else if (asBinaryExpression.NodeType == ExpressionType.AndAlso)
                    s += " and ";

                // X:\jsc.svn\examples\javascript\linq\test\TestWhereMathAdd\TestWhereMathAdd\ApplicationWebService.cs
                else if (asBinaryExpression.NodeType == ExpressionType.Add)
                    s += " + ";
                else if (asBinaryExpression.NodeType == ExpressionType.Subtract)
                    s += " - ";
                else if (asBinaryExpression.NodeType == ExpressionType.Multiply)
                    s += " * ";
                else if (asBinaryExpression.NodeType == ExpressionType.Divide)
                    s += " / ";

                else
                    Debugger.Break();
                #endregion

                state.WriteExpression(ref s, asBinaryExpression.Right, that);
                s += ")";
                return;
            }
            #endregion


            #region asConstantExpression
            var asConstantExpression = asExpression as ConstantExpression;
            if (asConstantExpression != null)
            {
                var __value = asConstantExpression.Value;

                WriteExpressionConstantCounter++;
                var n = "@arg" + WriteExpressionConstantCounter;
                s += n;

                state.ApplyParameter.Add(c => c.AddParameter(n, __value));
                return;
            }
            #endregion


            #region WriteExpression:asMemberExpression
            var asMemberExpression = asExpression as MemberExpression;
            if (asMemberExpression != null)
            {
                // arg1 = {value(TestWhereContains.ApplicationWebService+<>c__DisplayClass0).z.u.n}
                // are we supposed to find that constant?

                #region GetValue
                var GetValue = default(Func<object>);

                #region xConstantExpression
                Action<MemberExpression, Action<object>> yy = null;

                yy = (x, yield) =>
                {
                    #region atyield
                    Action<object> atyield =
                        __value =>
                        {
                            var xPropertyInfo = x.Member as PropertyInfo;
                            if (xPropertyInfo != null)
                            {
                                yield(
                                    xPropertyInfo.GetValue(__value, null)
                                );
                                return;
                            }


                            var xFieldInfo = x.Member as FieldInfo;
                            if (xFieldInfo != null)
                            {
                                yield(
                                    xFieldInfo.GetValue(__value)
                                );
                                // __value2 = { u = { n = C } }
                                return;
                            }
                        };
                    #endregion


                    var xConstantExpression = x.Expression as ConstantExpression;
                    if (xConstantExpression != null)
                    {
                        // z = { u = { n = C } }
                        atyield(xConstantExpression.Value);
                    }


                    if (x.Expression is MemberExpression)
                        yy(x.Expression as MemberExpression, atyield);
                };
                #endregion

                yy(asMemberExpression,
                     __value =>
                    {
                        GetValue = () => __value;
                    }
                );

                if (GetValue != null)
                {
                    var __value = GetValue();

                    WriteExpressionConstantCounter++;
                    var n = "@arg" + WriteExpressionConstantCounter;
                    s += n;

                    state.ApplyParameter.Add(c => c.AddParameter(n, __value));
                    return;
                }
                #endregion


                // are we looking at a group?
                // asMemberExpression = {gg.Key.domComplete}


                // where (`domComplete`=(`domComplete` - @arg3))


                var currentSelect = (that as QueryStrategyOfTRowExtensions.INestedQueryStrategy).upperSelect;
                if (currentSelect != null)
                {
                    var currentGroup = (that as QueryStrategyOfTRowExtensions.INestedQueryStrategy).upperSelect.upperGroupBy;
                    if (currentGroup != null)
                    {
                        // keySelector = {x => new <>f__AnonymousType1`1(domComplete = x.domComplete)}

                        var gguser = currentGroup.upperSelect.selectorExpression as LambdaExpression;
                        // [0] = {gg}

                        var xMemberExpression = asMemberExpression.Expression as MemberExpression;
                        if (xMemberExpression != null)
                        {
                            // xMemberExpression = {gg.Key}
                            var xMParameterExpression = xMemberExpression.Expression as ParameterExpression;

                            if (xMParameterExpression.Name == gguser.Parameters[0].Name)
                            {
                                // are we talking about the group key member?

                                // thats not available inside here yet

                                var xNewExpression = (currentGroup.keySelector as LambdaExpression).Body as NewExpression;

                                // xNewExpression = {new <>f__AnonymousType1`1(goo = x.domComplete)}
                                // asMemberExpression = {gg.Key.goo}

                                var i = xNewExpression.Members.IndexOf(z => z.Name == asMemberExpression.Member.Name);


                                // group by, the inner source
                                s += "s";
                                s += ".";


                                s += "`";
                                s += "" + (xNewExpression.Arguments[i] as MemberExpression).Member.Name;
                                s += "`";
                                return;
                            }
                        }
                    }


                    var xParameterExpression = asMemberExpression.Expression as ParameterExpression;
                    if (xParameterExpression != null)
                    {

                        var xLambdaExpression = ((that as QueryStrategyOfTRowExtensions.INestedQueryStrategy).upperSelect.selectorExpression as LambdaExpression);
                        if (xLambdaExpression.Parameters[0].Name == xParameterExpression.Name)
                        {
                            // local?
                        }
                        else
                        {

                            // selecting it as we speak..?
                            s += "" + xParameterExpression.Name;
                            s += ".";
                        }
                    }
                }
                else
                {
                    // ?
                }

                s += "`";
                s += "" + asMemberExpression.Member.Name;
                s += "`";
                return;
            }
            #endregion


            #region WriteExpression::UnaryExpression
            var asUnaryExpression = asExpression as UnaryExpression;
            if (asUnaryExpression != null)
            {
                if (asUnaryExpression.NodeType == ExpressionType.Convert)
                {
                    // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectOrUnaryExpression\TestSelectOrUnaryExpression\ApplicationWebService.cs
                    state.WriteExpression(ref s, asUnaryExpression.Operand, that);
                }
                else if (asUnaryExpression.NodeType == ExpressionType.Not)
                {

                    s += "not(";

                    state.WriteExpression(ref s, asUnaryExpression.Operand, that);

                    s += ")";
                }
                else Debugger.Break();

                return;
            }
            #endregion



            // asExpression = {IsNullOrEmpty(x.path)}


            #region WriteExpression:asMethodCallExpression
            var asMethodCallExpression = asExpression as MethodCallExpression;
            if (asMethodCallExpression != null)
            {
                // now what?

                if (asMethodCallExpression.Method.DeclaringType == typeof(string))
                {
                    // asMethodCallExpression.Method = {Boolean Contains(System.String)}

                    #region refToLower
                    var refToLower = new Func<string>("".ToLower).Method;
                    if (refToLower.Name == asMethodCallExpression.Method.Name)
                    {
                        s += "lower(";

                        var arg0 = asMethodCallExpression.Object;
                        state.WriteExpression(ref s, arg0, that);

                        s += ")";
                        return;
                    }
                    #endregion


                    #region refToUpper
                    var refToUpper = new Func<string>("".ToUpper).Method;
                    if (refToUpper.Name == asMethodCallExpression.Method.Name)
                    {
                        s += "upper(";

                        var arg0 = asMethodCallExpression.Object;
                        state.WriteExpression(ref s, arg0, that);

                        s += ")";
                        return;
                    }
                    #endregion


                    #region refContains
                    var refContains = new Func<string, bool>("".Contains).Method;
                    if (refContains.Name == asMethodCallExpression.Method.Name)
                    {
                        var arg1 = asMethodCallExpression.Arguments[0];
                        // arg1 = {"C"}
                        var arg0 = asMethodCallExpression.Object;
                        // arg0 = {x.path}


                        s += "(replace(";

                        state.WriteExpression(ref s, arg0, that);
                        s += ", ";

                        state.WriteExpression(ref s, arg1, that);

                        s += ", '')<>";

                        state.WriteExpression(ref s, arg0, that);
                        s += ")";

                        return;
                    }
                    #endregion


                    #region refIsNullOrEmpty
                    var refIsNullOrEmpty = new Func<string, bool>(string.IsNullOrEmpty).Method;
                    if (refIsNullOrEmpty.Name == asMethodCallExpression.Method.Name)
                    {
                        // the first method

                        // [0] = {x.path}
                        var arg1 = asMethodCallExpression.Arguments[0] as MemberExpression;

                        var xColumnName0 = arg1.Member.Name;

                        // ?
                        s += "`" + xColumnName0 + "` is null or length(`" + xColumnName0 + "`) = 0";

                        return;
                    }
                    #endregion

                }

                Debugger.Break();
            }
            #endregion



            Debugger.Break();
        }
 public SimpleRepositoryQueryEvent(IQueryRepository repository, IQueryStrategy queryStrategy, object additionalQueryData)
     : this(repository, queryStrategy, additionalQueryData, null)
 {
 }
 public GetEntityRepositoryQueryEvent(IQueryRepository repository, IQueryStrategy specification, IQueryStrategy queryStrategy, object additionalQueryData, bool? throwExceptionIfZeroOrManyFound)
     : base(repository, specification, queryStrategy, additionalQueryData, throwExceptionIfZeroOrManyFound)
 {
 }
        public GetEntityRepositoryQueryEvent(IQueryRepository repository, IQueryStrategy specification, IQueryStrategy queryStrategy, object additionalQueryData)
            : this(repository, specification, queryStrategy, additionalQueryData, null)
        {

        }
 protected SimpleRepositoryQueryEvent(IQueryRepository repository, IQueryStrategy specificationStrategy, IQueryStrategy queryStrategy, object additionalQueryData)
     : this(repository, specificationStrategy, queryStrategy, additionalQueryData, null)
 {
 }