I accept proposals for a most suitable name :-). Names are important.
Some proposals:
- ModifyCommand
- TargetCommand
- UpdateCommand

I'm very bad making suitable names.

Regards.

On Sun, Oct 12, 2008 at 11:03 PM, Pascal Craponne <[EMAIL PROTECTED]> wrote:
> Hi Pablo,
> I kinda like the patch, and have no objection on it (except maybe the
> spelling of "parameterized" word :)).
> Pascal.
>
> On Thu, Oct 9, 2008 at 16:10, Pablo Iñigo Blasco <[EMAIL PROTECTED]> wrote:
>>
>> Hi. Excuse me, I was late.
>>
>> With this patch you can use the DataContext.GetCommand(IQueryable). I
>> have no commited changes because I want to know your opinion about
>> such changes. Take a look please!
>>
>> - The main objective is to move some responsabilities from QueryRunner
>> to AbstractCommand, SelectCommand since QueryRunner usually executes
>> the DbCommand
>>
>> - QueryRunner.DbCommand subclass has been extracted as a new class in
>> System.Data.Linq.Database and System.Data.Linq.Database.Implementation
>>
>> - Some repetitive code in QueryRunner has been moved to XXCommand.
>>
>>
>> Regards.
>>
>> Index: src/DbLinq/Data/Linq/Database/IDbLinqCommand.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Database/IDbLinqCommand.cs     (revision 0)
>> +++ src/DbLinq/Data/Linq/Database/IDbLinqCommand.cs     (revision 0)
>> @@ -0,0 +1,23 @@
>> +using System;
>> +using System.Collections.Generic;
>> +using System.Linq;
>> +using System.Text;
>> +using System.Data;
>> +
>> +namespace DbLinq.Data.Linq.Database
>> +{
>> +#if MONO_STRICT
>> +    internal
>> +#else
>> +    public
>> +#endif
>> + interface IDbLinqCommand : IDisposable
>> +    {
>> +        IDbCommand Command { get; }
>> +        /// <summary>
>> +        /// Commits the current transaction.
>> +        /// throws NRE if _transaction is null. Behavior is intentional.
>> +        /// </summary>
>> +        void Commit();
>> +    }
>> +}
>> Index: src/DbLinq/Data/Linq/Database/Implementation/DbLinqCommand.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Database/Implementation/DbLinqCommand.cs
>> (revision 0)
>> +++ src/DbLinq/Data/Linq/Database/Implementation/DbLinqCommand.cs
>> (revision 0)
>> @@ -0,0 +1,88 @@
>> +#region MIT license
>> +//
>> +// MIT license
>> +//
>> +// Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
>> +//
>> +// Permission is hereby granted, free of charge, to any person obtaining
>> a copy
>> +// of this software and associated documentation files (the
>> "Software"), to deal
>> +// in the Software without restriction, including without limitation the
>> rights
>> +// to use, copy, modify, merge, publish, distribute, sublicense, and/or
>> sell
>> +// copies of the Software, and to permit persons to whom the Software is
>> +// furnished to do so, subject to the following conditions:
>> +//
>> +// The above copyright notice and this permission notice shall be
>> included in
>> +// all copies or substantial portions of the Software.
>> +//
>> +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> EXPRESS OR
>> +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> MERCHANTABILITY,
>> +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
>> SHALL THE
>> +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
>> ARISING FROM,
>> +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
>> IN
>> +// THE SOFTWARE.
>> +//
>> +#endregion
>> +using System;
>> +using System.Data;
>> +
>> +using System;
>> +
>> +#if MONO_STRICT
>> +using System.Data.Linq.Sql;
>> +using System.Data.Linq;
>> +#else
>> +using DbLinq.Data.Linq.Sql;
>> +#endif
>> +
>> +namespace DbLinq.Data.Linq.Database.Implementation
>> +{
>> +    public class DbLinqCommand : IDbLinqCommand
>> +    {
>> +        private IDisposable _connection;
>> +        private IDatabaseTransaction _transaction;
>> +        private readonly IDbCommand cmd;
>> +        public IDbCommand Command
>> +        {
>> +            get
>> +            {
>> +                return cmd;
>> +            }
>> +        }
>> +
>> +
>> +        public virtual void Dispose()
>> +        {
>> +            Command.Dispose();
>> +            if (_transaction != null)
>> +                _transaction.Dispose();
>> +            _connection.Dispose();
>> +        }
>> +
>> +        /// <summary>
>> +        /// Commits the current transaction.
>> +        /// throws NRE if _transaction is null. Behavior is intentional.
>> +        /// </summary>
>> +        public void Commit()
>> +        {
>> +            // TODO: do not commit if participating in a higher
>> transaction
>> +            _transaction.Commit();
>> +        }
>> +
>> +        public DbLinqCommand(string commandText, bool
>> createTransaction, DataContext dataContext)
>> +        {
>> +            // TODO: check if all this stuff is necessary
>> +            // the OpenConnection() checks that the connection is already
>> open
>> +            // TODO: see if we can move this here (in theory the
>> final DataContext shouldn't use)
>> +            _connection = dataContext.DatabaseContext.OpenConnection();
>> +            // the transaction is optional
>> +            if (createTransaction)
>> +                _transaction = dataContext.DatabaseContext.Transaction();
>> +            cmd = dataContext.DatabaseContext.CreateCommand();
>> +            Command.CommandText = commandText;
>> +            if (createTransaction)
>> +                Command.Transaction = _transaction.Transaction;
>> +        }
>> +
>> +    }
>> +}
>> Index: src/DbLinq/Data/Linq/DataContext.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/DataContext.cs (revision 904)
>> +++ src/DbLinq/Data/Linq/DataContext.cs (working copy)
>> @@ -133,7 +133,6 @@
>>
>>         private void Init(IDatabaseContext databaseContext,
>> MappingSource mappingSource, IVendor vendor)
>>         {
>> -
>>             if (databaseContext == null)
>>                 throw new ArgumentNullException("databaseContext");
>>
>> @@ -225,29 +224,29 @@
>>                 {
>>                     switch (entityTrack.EntityState)
>>                     {
>> -                    case EntityState.ToInsert:
>> -                        var insertQuery =
>> QueryBuilder.GetInsertQuery(entityTrack.Entity, queryContext);
>> -                        QueryRunner.Insert(entityTrack.Entity,
>> insertQuery);
>> -                        Register(entityTrack.Entity);
>> -                        break;
>> -                    case EntityState.ToWatch:
>> -                        if
>> (MemberModificationHandler.IsModified(entityTrack.Entity, Mapping))
>> -                        {
>> -                            var modifiedMembers =
>> MemberModificationHandler.GetModifiedProperties(entityTrack.Entity,
>> Mapping);
>> -                            var updateQuery =
>> QueryBuilder.GetUpdateQuery(entityTrack.Entity, modifiedMembers,
>> queryContext);
>> -                            QueryRunner.Update(entityTrack.Entity,
>> updateQuery, modifiedMembers);
>> +                        case EntityState.ToInsert:
>> +                            var insertQuery =
>> QueryBuilder.GetInsertQuery(entityTrack.Entity, queryContext);
>> +                            QueryRunner.Insert(entityTrack.Entity,
>> insertQuery);
>> +                            Register(entityTrack.Entity);
>> +                            break;
>> +                        case EntityState.ToWatch:
>> +                            if
>> (MemberModificationHandler.IsModified(entityTrack.Entity, Mapping))
>> +                            {
>> +                                var modifiedMembers =
>> MemberModificationHandler.GetModifiedProperties(entityTrack.Entity,
>> Mapping);
>> +                                var updateQuery =
>> QueryBuilder.GetUpdateQuery(entityTrack.Entity, modifiedMembers,
>> queryContext);
>> +
>> QueryRunner.Update(entityTrack.Entity, updateQuery, modifiedMembers);
>>
>> -                            RegisterUpdateAgain(entityTrack.Entity);
>> -                        }
>> -                        break;
>> -                    case EntityState.ToDelete:
>> -                        var deleteQuery =
>> QueryBuilder.GetDeleteQuery(entityTrack.Entity, queryContext);
>> -                        QueryRunner.Delete(entityTrack.Entity,
>> deleteQuery);
>> +                                RegisterUpdateAgain(entityTrack.Entity);
>> +                            }
>> +                            break;
>> +                        case EntityState.ToDelete:
>> +                            var deleteQuery =
>> QueryBuilder.GetDeleteQuery(entityTrack.Entity, queryContext);
>> +                            QueryRunner.Delete(entityTrack.Entity,
>> deleteQuery);
>>
>> -                        UnregisterDelete(entityTrack.Entity);
>> -                        break;
>> -                    default:
>> -                        throw new ArgumentOutOfRangeException();
>> +                            UnregisterDelete(entityTrack.Entity);
>> +                            break;
>> +                        default:
>> +                            throw new ArgumentOutOfRangeException();
>>                     }
>>                 }
>>                 // TODO: handle conflicts (which can only occur when
>> concurrency mode is implemented)
>> @@ -567,18 +566,18 @@
>>             {
>>                 switch (entityTrack.EntityState)
>>                 {
>> -                case EntityState.ToInsert:
>> -                    inserts.Add(entityTrack.Entity);
>> -                    break;
>> -                case EntityState.ToWatch:
>> -                    if
>> (MemberModificationHandler.IsModified(entityTrack.Entity, Mapping))
>> -                        updates.Add(entityTrack.Entity);
>> -                    break;
>> -                case EntityState.ToDelete:
>> -                    deletes.Add(entityTrack.Entity);
>> -                    break;
>> -                default:
>> -                    throw new ArgumentOutOfRangeException();
>> +                    case EntityState.ToInsert:
>> +                        inserts.Add(entityTrack.Entity);
>> +                        break;
>> +                    case EntityState.ToWatch:
>> +                        if
>> (MemberModificationHandler.IsModified(entityTrack.Entity, Mapping))
>> +                            updates.Add(entityTrack.Entity);
>> +                        break;
>> +                    case EntityState.ToDelete:
>> +                        deletes.Add(entityTrack.Entity);
>> +                        break;
>> +                    default:
>> +                        throw new ArgumentOutOfRangeException();
>>                 }
>>             }
>>             return new ChangeSet(inserts, updates, deletes);
>> @@ -741,7 +740,15 @@
>>         [DbLinqToDo]
>>         public DbCommand GetCommand(IQueryable query)
>>         {
>> -            throw new NotImplementedException();
>> +            QueryProvider qp = query.Provider as QueryProvider;
>> +            if (qp == null)
>> +                throw new InvalidOperationException();
>> +
>> +            IDbCommand dbCommand =
>> qp.GetQuery(null).GetCommand().Command;
>> +            if (!(dbCommand is DbCommand))
>> +                throw new InvalidOperationException();
>> +
>> +            return (DbCommand)dbCommand;
>>         }
>>
>>         [DbLinqToDo]
>> Index: src/DbLinq/Data/Linq/Implementation/QueryProvider.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Implementation/QueryProvider.cs        (revision
>> 904)
>> +++ src/DbLinq/Data/Linq/Implementation/QueryProvider.cs        (working
>> copy)
>> @@ -41,10 +41,11 @@
>>  namespace DbLinq.Data.Linq.Implementation
>>  #endif
>>  {
>> -    internal class QueryProvider
>> +    internal abstract class QueryProvider
>>     {
>>         public ExpressionChain ExpressionChain { get; set; }
>>         public Type TableType { get; set; }
>> +        public abstract SelectQuery GetQuery(Expression expression);
>>     }
>>
>>     internal class QueryProvider<T> : QueryProvider, IQueryProvider,
>> IQueryable<T>, IOrderedQueryable<T>
>> @@ -92,7 +93,7 @@
>>             return new QueryProvider<TElement>(TableType,
>> _dataContext, ExpressionChain, expression);
>>         }
>>
>> -        protected SelectQuery GetQuery(Expression expression)
>> +        public override SelectQuery GetQuery(Expression expression)
>>         {
>>             var expressionChain = ExpressionChain;
>>             if (expression != null)
>> Index: src/DbLinq/Data/Linq/Sugar/AbstractQuery.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/AbstractQuery.cs (revision 904)
>> +++ src/DbLinq/Data/Linq/Sugar/AbstractQuery.cs (working copy)
>> @@ -24,9 +24,14 @@
>>  //
>>  #endregion
>>
>> +using DbLinq.Util;
>> +using DbLinq.Data.Linq.Database;
>> +using System.Collections.Generic;
>> +
>>  #if MONO_STRICT
>>  using System.Data.Linq.Sql;
>>  #else
>> +using DbLinq.Data.Linq.Sugar.Expressions;
>>  using DbLinq.Data.Linq.Sql;
>>  #endif
>>
>> @@ -41,6 +46,13 @@
>>     /// </summary>
>>     internal abstract class AbstractQuery
>>     {
>> +        public abstract IDbLinqCommand GetCommand();
>> +
>> +        protected IDbLinqCommand GetCommand(bool createTransaction)
>> +        {
>> +            return new
>> DbLinq.Data.Linq.Database.Implementation.DbLinqCommand(Sql.ToString(),
>> createTransaction, DataContext);
>> +        }
>> +
>>         /// <summary>
>>         /// The DataContext from which the request originates
>>         /// </summary>
>> Index: src/DbLinq/Data/Linq/Sugar/DeleteQuery.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/DeleteQuery.cs   (revision 904)
>> +++ src/DbLinq/Data/Linq/Sugar/DeleteQuery.cs   (working copy)
>> @@ -39,14 +39,11 @@
>>  namespace DbLinq.Data.Linq.Sugar
>>  #endif
>>  {
>> -    internal class DeleteQuery : AbstractQuery
>> +    internal class DeleteQuery : ParametrizedQuery
>>     {
>> -        public IList<ObjectInputParameterExpression> InputParameters
>> { get; private set; }
>> -
>>         public DeleteQuery(DataContext dataContext, SqlStatement sql,
>> IList<ObjectInputParameterExpression> inputParameters)
>> -            : base(dataContext, sql)
>> +            : base(dataContext, sql, inputParameters)
>>         {
>> -            InputParameters = inputParameters;
>>         }
>>     }
>>  }
>> Index: src/DbLinq/Data/Linq/Sugar/DirectQuery.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/DirectQuery.cs   (revision 904)
>> +++ src/DbLinq/Data/Linq/Sugar/DirectQuery.cs   (working copy)
>> @@ -26,10 +26,14 @@
>>
>>  using System;
>>  using System.Collections.Generic;
>> +using DbLinq.Data.Linq.Database;
>> +using System.Data;
>> +
>>  #if MONO_STRICT
>>  using System.Data.Linq.Sql;
>>  #else
>>  using DbLinq.Data.Linq.Sql;
>> +using DbLinq.Util;
>>  #endif
>>
>>  #if MONO_STRICT
>> @@ -40,6 +44,7 @@
>>  {
>>     internal class DirectQuery : AbstractQuery
>>     {
>> +        public IList<object> parameterValues { get; set; }
>>         public IList<string> Parameters { get; private set; }
>>
>>         public DirectQuery(DataContext dataContext, SqlStatement sql,
>> IList<string> parameters)
>> @@ -47,5 +52,38 @@
>>         {
>>             Parameters = parameters;
>>         }
>> +
>> +        public override IDbLinqCommand GetCommand()
>> +        {
>> +            IDbLinqCommand command = base.GetCommand(false);
>> +            FeedParameters(command);
>> +            return command;
>> +        }
>> +
>> +        /// <summary>
>> +        /// Fills dbCommand parameters, given names and values
>> +        /// </summary>
>> +        /// <param name="dbCommand"></param>
>> +        /// <param name="parameterNames"></param>
>> +        /// <param name="parameterValues"></param>
>> +        private void FeedParameters(IDbLinqCommand command)
>> +        {
>> +            IDbCommand dbCommand = command.Command;
>> +            for (int parameterIndex = 0; parameterIndex <
>> Parameters.Count; parameterIndex++)
>> +            {
>> +                var dbParameter = dbCommand.CreateParameter();
>> +                dbParameter.ParameterName = Parameters[parameterIndex];
>> +
>> +                var value = parameterValues[parameterIndex];
>> +                if (value == null)
>> +                    dbParameter.Value = DBNull.Value;
>> +                else
>> +                    dbParameter.Value = value;
>> +
>> +                dbCommand.Parameters.Add(dbParameter);
>> +            }
>> +
>> +        }
>>     }
>> +
>>  }
>> Index: src/DbLinq/Data/Linq/Sugar/Implementation/QueryRunner.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/Implementation/QueryRunner.cs    (revision
>> 904)
>> +++ src/DbLinq/Data/Linq/Sugar/Implementation/QueryRunner.cs    (working
>> copy)
>> @@ -49,51 +49,6 @@
>>  {
>>     internal class QueryRunner : IQueryRunner
>>     {
>> -        protected class DbCommand : IDisposable
>> -        {
>> -            private IDisposable _connection;
>> -            private IDatabaseTransaction _transaction;
>> -            public readonly IDbCommand Command;
>> -
>> -            public virtual void Dispose()
>> -            {
>> -                Command.Dispose();
>> -                if (_transaction != null)
>> -                    _transaction.Dispose();
>> -                _connection.Dispose();
>> -            }
>> -
>> -            /// <summary>
>> -            /// Commits the current transaction.
>> -            /// throws NRE if _transaction is null. Behavior is
>> intentional.
>> -            /// </summary>
>> -            public void Commit()
>> -            {
>> -                // TODO: do not commit if participating in a higher
>> transaction
>> -                _transaction.Commit();
>> -            }
>> -
>> -            public DbCommand(string commandText, bool
>> createTransaction, DataContext dataContext)
>> -            {
>> -                // TODO: check if all this stuff is necessary
>> -                // the OpenConnection() checks that the connection is
>> already open
>> -                // TODO: see if we can move this here (in theory the
>> final DataContext shouldn't use)
>> -                _connection =
>> dataContext.DatabaseContext.OpenConnection();
>> -                // the transaction is optional
>> -                if (createTransaction)
>> -                    _transaction =
>> dataContext.DatabaseContext.Transaction();
>> -                Command = dataContext.DatabaseContext.CreateCommand();
>> -                Command.CommandText = commandText;
>> -                if (createTransaction)
>> -                    Command.Transaction = _transaction.Transaction;
>> -            }
>> -        }
>> -
>> -        protected virtual DbCommand UseDbCommand(SqlStatement
>> commandText, bool createTransaction, DataContext dataContext)
>> -        {
>> -            return new DbCommand(commandText.ToString(),
>> createTransaction, dataContext);
>> -        }
>> -
>>         /// <summary>
>>         /// Enumerates all records return by SQL request
>>         /// </summary>
>> @@ -111,15 +66,8 @@
>>                 yield break;
>>             }
>>
>> -            using (var dbCommand = UseDbCommand(selectQuery.Sql,
>> false, selectQuery.DataContext))
>> +            using (var dbCommand = selectQuery.GetCommand())
>>             {
>> -                foreach (var parameter in selectQuery.InputParameters)
>> -                {
>> -                    var dbParameter =
>> dbCommand.Command.CreateParameter();
>> -                    dbParameter.ParameterName =
>>
>> selectQuery.DataContext.Vendor.SqlProvider.GetParameterName(parameter.Alias);
>> -                    dbParameter.Value = parameter.GetValue();
>> -                    dbCommand.Command.Parameters.Add(dbParameter);
>> -                }
>>
>>                 // write query to log
>>                 selectQuery.DataContext.WriteLog(dbCommand.Command);
>> @@ -176,18 +124,18 @@
>>         {
>>             switch (selectQuery.ExecuteMethodName)
>>             {
>> -            case null: // some calls, like Count() generate SQL and
>> the resulting projection method name is null (never initialized)
>> -                return SelectSingle<S>(selectQuery, false); //
>> Single() for safety, but First() should work
>> -            case "First":
>> -                return SelectFirst<S>(selectQuery, false);
>> -            case "FirstOrDefault":
>> -                return SelectFirst<S>(selectQuery, true);
>> -            case "Single":
>> -                return SelectSingle<S>(selectQuery, false);
>> -            case "SingleOrDefault":
>> -                return SelectSingle<S>(selectQuery, true);
>> -            case "Last":
>> -                return SelectLast<S>(selectQuery, false);
>> +                case null: // some calls, like Count() generate SQL
>> and the resulting projection method name is null (never initialized)
>> +                    return SelectSingle<S>(selectQuery, false); //
>> Single() for safety, but First() should work
>> +                case "First":
>> +                    return SelectFirst<S>(selectQuery, false);
>> +                case "FirstOrDefault":
>> +                    return SelectFirst<S>(selectQuery, true);
>> +                case "Single":
>> +                    return SelectSingle<S>(selectQuery, false);
>> +                case "SingleOrDefault":
>> +                    return SelectSingle<S>(selectQuery, true);
>> +                case "Last":
>> +                    return SelectLast<S>(selectQuery, false);
>>             }
>>             throw Error.BadArgument("S0077: Unhandled method '{0}'",
>> selectQuery.ExecuteMethodName);
>>         }
>> @@ -267,17 +215,10 @@
>>
>>         private void Upsert(object target, UpsertQuery insertQuery)
>>         {
>> +            insertQuery.Target = target;
>>             var dataContext = insertQuery.DataContext;
>> -            var sqlProvider = dataContext.Vendor.SqlProvider;
>> -            using (var dbCommand = UseDbCommand(insertQuery.Sql,
>> true, dataContext))
>> +            using (var dbCommand = insertQuery.GetCommand())
>>             {
>> -                foreach (var inputParameter in
>> insertQuery.InputParameters)
>> -                {
>> -                    var dbParameter =
>> dbCommand.Command.CreateParameter();
>> -                    dbParameter.ParameterName =
>> sqlProvider.GetParameterName(inputParameter.Alias);
>> -
>> dbParameter.SetValue(inputParameter.GetValue(target),
>> inputParameter.ValueType);
>> -                    dbCommand.Command.Parameters.Add(dbParameter);
>> -                }
>>
>>                 // log first command
>>                 dataContext.WriteLog(dbCommand.Command);
>> @@ -343,16 +284,9 @@
>>         /// <param name="deleteQuery">SQL delete query</param>
>>         public void Delete(object target, DeleteQuery deleteQuery)
>>         {
>> -            var sqlProvider = deleteQuery.DataContext.Vendor.SqlProvider;
>> -            using (var dbCommand = UseDbCommand(deleteQuery.Sql,
>> true, deleteQuery.DataContext))
>> +            deleteQuery.Target = target;
>> +            using (var dbCommand = deleteQuery.GetCommand())
>>             {
>> -                foreach (var inputParameter in
>> deleteQuery.InputParameters)
>> -                {
>> -                    var dbParameter =
>> dbCommand.Command.CreateParameter();
>> -                    dbParameter.ParameterName =
>> sqlProvider.GetParameterName(inputParameter.Alias);
>> -
>> dbParameter.SetValue(inputParameter.GetValue(target),
>> inputParameter.ValueType);
>> -                    dbCommand.Command.Parameters.Add(dbParameter);
>> -                }
>>
>>                 // log command
>>                 deleteQuery.DataContext.WriteLog(dbCommand.Command);
>> @@ -387,9 +321,9 @@
>>         /// <returns></returns>
>>         public int Execute(DirectQuery directQuery, params object[]
>> parameters)
>>         {
>> -            using (var dbCommand = UseDbCommand(directQuery.Sql,
>> false, directQuery.DataContext))
>> +            directQuery.parameterValues = parameters;
>> +            using (var dbCommand = directQuery.GetCommand())
>>             {
>> -                FeedParameters(dbCommand.Command,
>> directQuery.Parameters, parameters);
>>
>>                 // log command
>>                 directQuery.DataContext.WriteLog(dbCommand.Command);
>> @@ -420,10 +354,9 @@
>>         /// <returns></returns>
>>         public IEnumerable ExecuteSelect(Type tableType, DirectQuery
>> directQuery, params object[] parameters)
>>         {
>> -            var dataContext = directQuery.DataContext;
>> -            using (var dbCommand = UseDbCommand(directQuery.Sql,
>> false, directQuery.DataContext))
>> +            directQuery.parameterValues = parameters;
>> +            using (var dbCommand = directQuery.GetCommand())
>>             {
>> -                FeedParameters(dbCommand.Command,
>> directQuery.Parameters, parameters);
>>
>>                 // log query
>>                 directQuery.DataContext.WriteLog(dbCommand.Command);
>> @@ -432,7 +365,7 @@
>>                 {
>>                     // Did you know? "return
>> EnumerateResult(tableType, dataReader, dataContext);" disposes
>> resources first
>>                     // before the enumerator is used
>> -                    foreach (var result in EnumerateResult(tableType,
>> dataReader, dataContext))
>> +                    foreach (var result in EnumerateResult(tableType,
>> dataReader, directQuery.DataContext))
>>                         yield return result;
>>                 }
>>             }
>> Index: src/DbLinq/Data/Linq/Sugar/ParametrizedQuery.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/ParametrizedQuery.cs     (revision 0)
>> +++ src/DbLinq/Data/Linq/Sugar/ParametrizedQuery.cs     (revision 0)
>> @@ -0,0 +1,73 @@
>> +#region MIT license
>> +//
>> +// MIT license
>> +//
>> +// Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
>> +//
>> +// Permission is hereby granted, free of charge, to any person obtaining
>> a copy
>> +// of this software and associated documentation files (the
>> "Software"), to deal
>> +// in the Software without restriction, including without limitation the
>> rights
>> +// to use, copy, modify, merge, publish, distribute, sublicense, and/or
>> sell
>> +// copies of the Software, and to permit persons to whom the Software is
>> +// furnished to do so, subject to the following conditions:
>> +//
>> +// The above copyright notice and this permission notice shall be
>> included in
>> +// all copies or substantial portions of the Software.
>> +//
>> +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> EXPRESS OR
>> +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> MERCHANTABILITY,
>> +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
>> SHALL THE
>> +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
>> ARISING FROM,
>> +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
>> IN
>> +// THE SOFTWARE.
>> +//
>> +#endregion
>> +
>> +using DbLinq.Util;
>> +using DbLinq.Data.Linq.Database;
>> +using System.Collections.Generic;
>> +
>> +#if MONO_STRICT
>> +using System.Data.Linq.Sql;
>> +using System.Data.Linq.Sugar.Expressions;
>> +#else
>> +using DbLinq.Data.Linq.Sql;
>> +using DbLinq.Data.Linq.Sugar.Expressions;
>> +#endif
>> +
>> +#if MONO_STRICT
>> +namespace System.Data.Linq.Sugar
>> +#else
>> +namespace DbLinq.Data.Linq.Sugar
>> +#endif
>> +{
>> +    internal abstract class ParametrizedQuery : AbstractQuery
>> +    {
>> +        protected ParametrizedQuery(DataContext dataContext,
>> SqlStatement sql, IList<ObjectInputParameterExpression>
>> inputParameters)
>> +            : base(dataContext, sql)
>> +        {
>> +            this.InputParameters = inputParameters;
>> +        }
>> +
>> +        /// <summary>
>> +        /// Parameters to be sent as SQL parameters
>> +        /// </summary>
>> +        public IList<ObjectInputParameterExpression> InputParameters
>> { get; protected set; }
>> +
>> +        public override IDbLinqCommand GetCommand()
>> +        {
>> +            IDbLinqCommand dbCommand = base.GetCommand(true);
>> +            foreach (var inputParameter in InputParameters)
>> +            {
>> +                var dbParameter = dbCommand.Command.CreateParameter();
>> +                dbParameter.ParameterName =
>> DataContext.Vendor.SqlProvider.GetParameterName(inputParameter.Alias);
>> +                dbParameter.SetValue(inputParameter.GetValue(Target),
>> inputParameter.ValueType);
>> +                dbCommand.Command.Parameters.Add(dbParameter);
>> +            }
>> +            return dbCommand;
>> +        }
>> +
>> +        public object Target { get; set; }
>> +    }
>> +}
>> Index: src/DbLinq/Data/Linq/Sugar/SelectQuery.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/SelectQuery.cs   (revision 904)
>> +++ src/DbLinq/Data/Linq/Sugar/SelectQuery.cs   (working copy)
>> @@ -27,6 +27,7 @@
>>  using System;
>>  using System.Collections.Generic;
>>  using System.Data;
>> +using DbLinq.Data.Linq.Database;
>>
>>  #if MONO_STRICT
>>  using System.Data.Linq.Sql;
>> @@ -48,7 +49,7 @@
>>     /// Represents a linq query, parsed and compiled, to be sent to
>> database
>>     /// This instance is immutable, since it can be stored in a cache
>>     /// </summary>
>> -    internal class SelectQuery: AbstractQuery
>> +    internal class SelectQuery : AbstractQuery
>>     {
>>         /// <summary>
>>         /// Parameters to be sent as SQL parameters
>> @@ -78,11 +79,24 @@
>>
>>         public SelectQuery(DataContext dataContext, SqlStatement sql,
>> IList<InputParameterExpression> parameters,
>>                      Delegate rowObjectCreator, string executeMethodName)
>> -            : base(dataContext,sql)
>> +            : base(dataContext, sql)
>>         {
>>             InputParameters = parameters;
>>             RowObjectCreator = rowObjectCreator;
>>             ExecuteMethodName = executeMethodName;
>>         }
>> +
>> +        public override IDbLinqCommand GetCommand()
>> +        {
>> +            var dbCommand = base.GetCommand(false);
>> +            foreach (var parameter in InputParameters)
>> +            {
>> +                var dbParameter = dbCommand.Command.CreateParameter();
>> +                dbParameter.ParameterName =
>> DataContext.Vendor.SqlProvider.GetParameterName(parameter.Alias);
>> +                dbParameter.Value = parameter.GetValue();
>> +                dbCommand.Command.Parameters.Add(dbParameter);
>> +            }
>> +            return dbCommand;
>> +        }
>>     }
>>  }
>> Index: src/DbLinq/Data/Linq/Sugar/UpsertQuery.cs
>> ===================================================================
>> --- src/DbLinq/Data/Linq/Sugar/UpsertQuery.cs   (revision 904)
>> +++ src/DbLinq/Data/Linq/Sugar/UpsertQuery.cs   (working copy)
>> @@ -39,14 +39,9 @@
>>  namespace DbLinq.Data.Linq.Sugar
>>  #endif
>>  {
>> -    internal class UpsertQuery : AbstractQuery
>> +    internal class UpsertQuery : ParametrizedQuery
>>     {
>>         /// <summary>
>> -        /// Input parameters, instance based (the instance being the
>> entity)
>> -        /// </summary>
>> -        public IList<ObjectInputParameterExpression> InputParameters
>> { get; private set; }
>> -
>> -        /// <summary>
>>         /// Output parameters, intstance based (the instance being the
>> entity)
>>         /// </summary>
>>         public IList<ObjectOutputParameterExpression>
>> OutputParameters { get; private set; }
>> @@ -58,9 +53,8 @@
>>
>>         public UpsertQuery(DataContext dataContext, SqlStatement sql,
>> SqlStatement idQuerySql, IList<ObjectInputParameterExpression>
>> inputParameters,
>>             IList<ObjectOutputParameterExpression> outputParameters)
>> -            : base(dataContext, sql)
>> +            : base(dataContext, sql,inputParameters)
>>         {
>> -            InputParameters = inputParameters;
>>             OutputParameters = outputParameters;
>>             IdQuerySql = idQuerySql;
>>         }
>> Index: src/DbLinq/DbLinq.csproj
>> ===================================================================
>> --- src/DbLinq/DbLinq.csproj    (revision 904)
>> +++ src/DbLinq/DbLinq.csproj    (working copy)
>> @@ -2,7 +2,7 @@
>>   <PropertyGroup>
>>     <Configuration Condition=" '$(Configuration)' == ''
>> ">Debug</Configuration>
>>     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
>> -    <ProductVersion>9.0.30729</ProductVersion>
>> +    <ProductVersion>9.0.21022</ProductVersion>
>>     <SchemaVersion>2.0</SchemaVersion>
>>     <ProjectGuid>{7950197D-4122-49CB-9FD7-45E666BAFEC2}</ProjectGuid>
>>     <OutputType>Library</OutputType>
>> @@ -62,6 +62,7 @@
>>     <Compile Include="Data\Linq\ChangeSet.cs" />
>>     <Compile Include="Data\Linq\Database\IDatabaseContext.cs" />
>>     <Compile Include="Data\Linq\Database\IDatabaseTransaction.cs" />
>> +    <Compile Include="Data\Linq\Database\IDbLinqCommand.cs" />
>>     <Compile
>> Include="Data\Linq\Database\Implementation\DatabaseConnection.cs"
>> />
>>     <Compile
>> Include="Data\Linq\Database\Implementation\DatabaseContext.cs" />
>>     <Compile
>> Include="Data\Linq\Database\Implementation\DatabaseTransaction.cs"
>> />
>> @@ -113,6 +114,7 @@
>>     <Compile Include="Data\Linq\Sql\SqlPart.cs" />
>>     <Compile Include="Data\Linq\Sql\SqlStatement.cs" />
>>     <Compile Include="Data\Linq\Sugar\BuilderContext.cs" />
>> +    <Compile Include="Data\Linq\Database\Implementation\DbLinqCommand.cs"
>> />
>>     <Compile Include="Data\Linq\Sugar\DeleteQuery.cs" />
>>     <Compile Include="Data\Linq\Sugar\DirectQuery.cs" />
>>     <Compile Include="Data\Linq\Sugar\Error.cs" />
>> @@ -139,6 +141,7 @@
>>     <Compile
>> Include="Data\Linq\Sugar\ExpressionMutator\Implementation\TypeBinaryExpressionMutator.cs"
>> />
>>     <Compile
>> Include="Data\Linq\Sugar\ExpressionMutator\Implementation\UnaryExpressionMutator.cs"
>> />
>>     <Compile Include="Data\Linq\Sugar\ExpressionPrecedence.cs" />
>> +    <Compile Include="Data\Linq\Sugar\ParametrizedQuery.cs" />
>>     <Compile Include="Data\Linq\Sugar\ExpressionQuery.cs" />
>>     <Compile Include="Data\Linq\Sugar\Expressions\ColumnExpression.cs" />
>>     <Compile
>> Include="Data\Linq\Sugar\Expressions\ObjectInputParameterExpression.cs"
>> />
>> Index: src/DbLinq/System.Data.Linq.csproj
>> ===================================================================
>> --- src/DbLinq/System.Data.Linq.csproj  (revision 904)
>> +++ src/DbLinq/System.Data.Linq.csproj  (working copy)
>> @@ -2,7 +2,7 @@
>>   <PropertyGroup>
>>     <Configuration Condition=" '$(Configuration)' == ''
>> ">Debug</Configuration>
>>     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
>> -    <ProductVersion>9.0.30729</ProductVersion>
>> +    <ProductVersion>9.0.21022</ProductVersion>
>>     <SchemaVersion>2.0</SchemaVersion>
>>     <ProjectGuid>{97305421-3071-4175-AA3C-9A432CC28121}</ProjectGuid>
>>     <OutputType>Library</OutputType>
>> @@ -56,9 +56,11 @@
>>     <Compile Include="Data\Linq\ChangeSet.cs" />
>>     <Compile Include="Data\Linq\Database\IDatabaseContext.cs" />
>>     <Compile Include="Data\Linq\Database\IDatabaseTransaction.cs" />
>> +    <Compile Include="Data\Linq\Database\IDbLinqCommand.cs" />
>>     <Compile
>> Include="Data\Linq\Database\Implementation\DatabaseConnection.cs"
>> />
>>     <Compile
>> Include="Data\Linq\Database\Implementation\DatabaseContext.cs" />
>>     <Compile
>> Include="Data\Linq\Database\Implementation\DatabaseTransaction.cs"
>> />
>> +    <Compile Include="Data\Linq\Database\Implementation\DbLinqCommand.cs"
>> />
>>     <Compile Include="Data\Linq\DataContext.cs" />
>>     <Compile Include="Data\Linq\DBLinqExtendedAttributte.cs" />
>>     <Compile Include="Data\Linq\EntityList.cs" />
>> @@ -180,6 +182,7 @@
>>     <Compile Include="Data\Linq\Sugar\ISpecialExpressionTranslator.cs" />
>>     <Compile Include="Data\Linq\Sugar\ISqlBuilder.cs" />
>>     <Compile Include="Data\Linq\Sugar\AbstractQuery.cs" />
>> +    <Compile Include="Data\Linq\Sugar\ParametrizedQuery.cs" />
>>     <Compile Include="Data\Linq\Sugar\SelectQuery.cs" />
>>     <Compile Include="Data\Linq\Sugar\QueryContext.cs" />
>>     <Compile Include="Data\Linq\Sugar\UpsertQuery.cs" />
>> Index: tests/Test_NUnit/ReadTest.cs
>> ===================================================================
>> --- tests/Test_NUnit/ReadTest.cs        (revision 899)
>> +++ tests/Test_NUnit/ReadTest.cs        (working copy)
>> @@ -58,7 +58,7 @@
>>  #if MONO_STRICT
>>     namespace Test_NUnit_MsSql_Strict
>>  #else
>> -    namespace Test_NUnit_MsSql
>> +namespace Test_NUnit_MsSql
>>  #endif
>>  #else
>>  #error unknown target
>> @@ -631,6 +631,5 @@
>>             Product p1 = db.Products.Single(p => p.ProductID == 1);
>>             Assert.IsTrue(p1.ProductID == 1);
>>         }
>> -
>>     }
>>  }
>> Index: tests/Test_NUnit/ReadTests_ReferenceLoading.cs
>> ===================================================================
>> --- tests/Test_NUnit/ReadTests_ReferenceLoading.cs      (revision 899)
>> +++ tests/Test_NUnit/ReadTests_ReferenceLoading.cs      (working copy)
>> @@ -136,5 +136,14 @@
>>             var list = q.ToList();
>>             Assert.AreEqual(db.Orders.Count(), list.Count);
>>         }
>> +
>> +        [Test]
>> +        public void ComplexProjection07()
>> +        {
>> +            var db = CreateDB();
>> +            var q = db.Employees.Select(e => e.Orders.Select(o=>o));
>> +
>> +            var list = q.ToList();
>> +        }
>>     }
>>  }
>> Index: tests/Test_NUnit/Test_NUnit_MsSql.csproj
>> ===================================================================
>> --- tests/Test_NUnit/Test_NUnit_MsSql.csproj    (revision 899)
>> +++ tests/Test_NUnit/Test_NUnit_MsSql.csproj    (working copy)
>> @@ -2,7 +2,7 @@
>>   <PropertyGroup>
>>     <Configuration Condition=" '$(Configuration)' == ''
>> ">Debug</Configuration>
>>     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
>> -    <ProductVersion>9.0.30729</ProductVersion>
>> +    <ProductVersion>9.0.21022</ProductVersion>
>>     <SchemaVersion>2.0</SchemaVersion>
>>     <ProjectGuid>{A348FBCE-2246-48FF-9862-35553B4B284C}</ProjectGuid>
>>     <OutputType>Library</OutputType>
>> @@ -68,6 +68,7 @@
>>     </Compile>
>>     <Compile Include="Attach.cs" />
>>     <Compile Include="CompositePK_Test.cs" />
>> +    <Compile Include="DataContext.cs" />
>>     <Compile Include="ReadTests_AnyCountFirst.cs" />
>>     <Compile Include="ReadTests_Conversions.cs" />
>>     <Compile Include="ReadTests_DateTimeFunctions.cs" />
>>
>>
>>
>>
>>
>> On Sun, Sep 21, 2008 at 12:19 PM,  <[EMAIL PROTECTED]> wrote:
>> > I'll try to implement it!
>> >
>> > Regards.
>> >
>> > On 9/21/08, Pascal Craponne <[EMAIL PROTECTED]> wrote:
>> >> Hi Andrus,
>> >> there's a GetCommand() method in DataContext. Unfortunately it is not
>> >> implemented yet :(
>> >> Anyway it should be quite easy to implement... Any volunteer?
>> >>
>> >> Pascal.
>> >>
>> >> On Sun, Sep 21, 2008 at 10:08, Andrus <[EMAIL PROTECTED]> wrote:
>> >>
>> >>>
>> >>> I need to pass DbLinq query to RDLDEsigner.
>> >>> RDLDesigner does not accept IQueryable<T>.
>> >>> It accepts SQL select statement in plain text format as data source.
>> >>>
>> >>> How to get SELECT statement which corresponds to DbLinq query
>> >>> as plain text as it is being sent to server ?
>> >>>
>> >>> How to create method which allows to grab the sql statement which is
>> >>> being
>> >>> passed to DataReader without executing DataReader and opening
>> >>> connection?
>> >>>
>> >>> Something like
>> >>>
>> >>> Northwind.Customers.Select().GetCommandText()
>> >>>
>> >>>
>> >>> Andrus.
>> >>>
>> >>>
>> >>> >
>> >>>
>> >>
>> >>
>> >> --
>> >> Pascal.
>> >>
>> >> jabber/gtalk: [EMAIL PROTECTED]
>> >> msn: [EMAIL PROTECTED]
>> >>
>> >> >>
>> >>
>> >
>> >
>> > --
>> > Saludos. Pablo Iñigo Blasco .
>> >
>>
>>
>>
>> --
>> Saludos. Pablo Iñigo Blasco .
>>
>>
>
>
>
> --
> Pascal.
>
> jabber/gtalk: [EMAIL PROTECTED]
> msn: [EMAIL PROTECTED]
>
>
> >
>



-- 
Saludos. Pablo Iñigo Blasco .

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to