public static IDbCommand CreateCommand <TEntity>(this DeleteFrom <TEntity> query, IDbConnection connection) { var command = connection.CreateCommand(); command.CommandText = query.ToString(); foreach (var condition in query.Where) { var parameter = command.CreateParameter(); parameter.ParameterName = query.NamingConvention.GetParameterName(condition.Column); parameter.Value = condition.Value; command.Parameters.Add(parameter); } return(command); }
public static DeleteFrom <TEntity> DeleteFrom <TEntity>(string key) { var query = new DeleteFrom <TEntity>(); var type = typeof(TEntity); query.Table = type.Name; var properties = type.GetProperties().ToList(); if (properties.Any(item => item.Name == key)) { query.Key = key; } query.Where.Add(new Condition { Column = key, ComparisonOperator = ComparisonOperator.Equals, Value = key }); return(query); }
public static DeleteFrom <TEntity> DeleteFrom <TEntity>(TEntity entity, string schema = null, string table = null, string key = null, IDatabaseNamingConvention dbNamingConvention = null) { var type = typeof(TEntity); var query = new DeleteFrom <TEntity> { NamingConvention = dbNamingConvention ?? DatabaseNamingConvention, Schema = schema, Table = string.IsNullOrEmpty(table) ? type.Name : table }; var properties = type.GetProperties().ToList(); if (properties.Any(item => item.Name == key)) { query.Key = key; } query.Where.Add(new Condition(key, ComparisonOperator.Equals, type.GetProperty(key).GetValue(entity))); return(query); }