public static string CreateByType(IDbCommand command, BinaryExpression exp, EntityStruct obj) { var type = obj.Key; var tableName = CommonCommandBuilder.GetTableName(type); var cmdBulder = new StringBuilder(string.Format(@" UPDATE [{0}].[{1}].[{2}] ", command.Connection.Database, CommonCommandBuilder.DbSchemaName, tableName)); var nameValuePairs = CommonCommandBuilder.FieldByValueClauseBuilder(type, obj.Value); var parameterizatedNames = nameValuePairs.Select( x => new KeyValuePair <string, string>(x.Key, CommonCommandBuilder.GetParamsFormat(x.Key, x.Value, command.Connection.Database)) ); foreach (var pair in nameValuePairs) { var prop = CommonCommandBuilder.GetPropertyByAttrName(type, pair.Key); var parameter = command.CreateParameter(); parameter.ParameterName = CommonCommandBuilder.GetParamsFormat(pair.Key, pair.Value, command.Connection.Database); parameter.DbType = TypeMap[prop.PropertyType]; parameter.Value = pair.Value; if (!command.Parameters.Contains(parameter.ParameterName)) { command.Parameters.Add(parameter); } } var updateClause = string.Join(",", parameterizatedNames.Select(x => string.Format(" [{0}].[{1}] = {2}", tableName, x.Key, x.Value))); cmdBulder.Append(string.Format(" SET {0} WHERE {1}", updateClause.Trim(','), CommonCommandBuilder.BuildClauseByExpression(command, type, exp))); return(cmdBulder.ToString()); }
public static string Create <T>(IDbCommand command, BinaryExpression exp) where T : class, IEntity, new() { var type = typeof(T); var selectBody = CreateBody(command.Connection.Database, type); return(string.Format("{0} WHERE {1}", selectBody, CommonCommandBuilder.BuildClauseByExpression(command, type, exp))); }
private static string CreateByType(IDbCommand command, BinaryExpression exp, Type type) { var tableName = CommonCommandBuilder.GetTableName(type); var cmdBulder = new StringBuilder( string.Format(@" DELETE FROM [{0}].[{1}].[{2}] ", command.Connection.Database, CommonCommandBuilder.DbSchemaName, tableName)); cmdBulder.Append(string.Format(" WHERE {0}", CommonCommandBuilder.BuildClauseByExpression(command, type, exp))); return(cmdBulder.ToString()); }