public static QueryData ToSqlString(this ObjectQuery objectQuery)
        {
            QueryData sqlOptions = new QueryData();

            string sql = objectQuery.ToTraceString();

            var sb = new StringBuilder();
            if (objectQuery.Context != null && objectQuery.Context.Connection != null && objectQuery.Context.Connection is EntityConnection)
                sqlOptions.ConnectionString = (objectQuery.Context.Connection as EntityConnection).StoreConnection.ConnectionString;

            foreach (ObjectParameter parameter in objectQuery.Parameters)
            {
                SqlParameter r = new SqlParameter(parameter.ParameterType.FullName, parameter.Value);

                sb.AppendLine(string.Format("DECLARE @{0} {1};", parameter.Name, r.SqlDbType));
                sb.AppendLine(string.Format("SET @{0} = '{1}';", parameter.Name, parameter.Value));
            }

            sb.AppendLine();
            sb.AppendLine(sql);

            sqlOptions.SQLCommand = sb.ToString();

            return sqlOptions;
        }
 public override void GetData(object target, Stream outgoingData)
 {
     QueryData sqlString = null;
     try
     {
         if (target as ObjectQuery == null)
         {
             if (target as ObjectContext != null)
             {
                 sqlString = (target as ObjectContext).ToSqlString();
             }
         }
         else
         {
             sqlString = (target as ObjectQuery).ToSqlString();
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         sqlString = new QueryData();
         sqlString.SetExceptionMessage(exception);
     }
     BinaryFormatter binaryFormatter = new BinaryFormatter();
     binaryFormatter.Serialize(outgoingData, sqlString);
 }
        public static QueryData ToSqlString(this ObjectContext objectContext)
        {
            QueryData sQLQueryOption = new QueryData();
            sQLQueryOption.ConnectionString = (objectContext.Connection as EntityConnection).StoreConnection.ConnectionString;
            sQLQueryOption.SQLCommand = GetSQLCommands(objectContext);

            return sQLQueryOption;
        }
 internal static QueryData ToSqlString(this DbContext dbContext)
 {
     var sqlOptions = new QueryData();
     var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
     sqlOptions.ConnectionString = (objectContext.Connection as EntityConnection).StoreConnection.ConnectionString;
     sqlOptions.SQLCommand = GetSQLCommands(objectContext);
     return sqlOptions;
 }