public static int UpdateData(
     Expression <Func <K, P> > select,
     Expression <Func <K, bool> > where,
     P newValue,
     string leafTable,
     GetDatabaseFieldNameDelegate getField,
     bool hasModifyAudit,
     ContextStartup startup,
     string connectionString
     )
 {
     using (var connection = Gravitybox.gFileSystem.EFDAL.DBHelper.GetConnection(Gravitybox.gFileSystem.EFDAL.Util.StripEFCS2Normal(connectionString)))
     {
         connection.Open();
         return(UpdateData(
                    select,
                    where,
                    newValue,
                    leafTable,
                    getField,
                    hasModifyAudit,
                    startup,
                    connection,
                    null));
     }
 }
 public static int UpdateData(
     Expression <Func <K, P> > select,
     Expression <Func <K, bool> > where,
     IBusinessObject newValue,
     string leafTable,
     GetDatabaseFieldNameDelegate getField,
     bool hasModifyAudit,
     string connectionString = ""
     )
 {
     if (string.IsNullOrEmpty(connectionString))
     {
         connectionString = Gravitybox.gFileSystem.EFDAL.gFileSystemEntities.GetConnectionString();
     }
     using (var connection = Gravitybox.gFileSystem.EFDAL.DBHelper.GetConnection(Gravitybox.gFileSystem.EFDAL.Util.StripEFCS2Normal(connectionString)))
     {
         connection.Open();
         return(UpdateData(
                    select,
                    where,
                    newValue,
                    leafTable,
                    getField,
                    hasModifyAudit,
                    null, connection, null));
     }
 }
 public static int UpdateData(
     Expression <Func <K, P> > select,
     Expression <Func <K, bool> > where,
     P newValue,
     string leafTable,
     GetDatabaseFieldNameDelegate getField,
     bool hasModifyAudit
     )
 {
     return(UpdateData(
                select,
                where,
                newValue,
                leafTable,
                getField,
                hasModifyAudit,
                Gravitybox.gFileSystem.EFDAL.gFileSystemEntities.GetConnectionString()));
 }
 public static int UpdateData(
     Expression <Func <K, P> > select,
     Expression <Func <K, bool> > where,
     P newValue,
     string leafTable,
     GetDatabaseFieldNameDelegate getField,
     bool hasModifyAudit,
     ContextStartup startup,
     IDbConnection connection,
     System.Data.Common.DbTransaction transaction
     )
 {
     if (startup == null)
     {
         startup = new ContextStartup(null);
     }
     using (var dc = new DataContext(connection))
     {
         var template = dc.GetTable <K>();
         using (var cmd = BusinessEntityQuery.GetCommand <K, P>(dc, template, select, where))
         {
             if (!startup.DefaultTimeout && startup.CommandTimeout > 0)
             {
                 cmd.CommandTimeout = startup.CommandTimeout;
             }
             else
             {
                 cmd.CommandTimeout = DEFAULTTIMEOUT;
             }
             if (transaction != null)
             {
                 cmd.Transaction = transaction;
             }
             var parser    = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.Table);
             var fieldName = parser.GetSelectClause();
             var sql       = "UPDATE [" + parser.GetTableAlias(fieldName, leafTable) + "]\r\n";
             sql += "SET [" + parser.GetTableAlias(fieldName, leafTable) + "].[" + fieldName + "] = @newValue\r\n";
             if (hasModifyAudit && (fieldName != "ModifiedBy"))
             {
                 sql += ", [" + parser.GetTableAlias(fieldName, leafTable) + "].[ModifiedBy] = NULL\r\n";
             }
             if (hasModifyAudit && (fieldName != "ModifiedDate"))
             {
                 sql += ", [" + parser.GetTableAlias(fieldName, leafTable) + "].[ModifiedDate] = sysdatetime()\r\n";
             }
             sql            += parser.GetFromClause(new QueryOptimizer()) + "\r\n";
             sql            += parser.GetWhereClause();
             sql            += ";select @@rowcount";
             sql             = "set ansi_nulls off;" + sql;
             cmd.CommandText = sql;
             if (newValue == null)
             {
                 cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("newValue", System.DBNull.Value));
             }
             else
             {
                 cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("newValue", newValue));
             }
             object p = cmd.ExecuteScalar();
             return((int)p);
         }
     }
 }