public ITableDelete <T> Delete <T>(string connectionString, string tableAlias) where T : class { var entityType = typeof(T); var em = EntityMapCache.GetEntityMap(entityType); if (StringHelper.IsNullOrEmptyOrBlankString(tableAlias) && em != null && em.Table != null) { tableAlias = em.Table.TableName; } ITableDeleteCommand command = new TableDeleteCommand(); command.CommandTextDelete = this.DataProvider.TableCommandGenerator.Delete(tableAlias); command.ConnectionString = connectionString; return(new TableDelete <T>(this, command)); }
public ITableActResult Delete <T>(string connectionString, T entity, string tableAlias) where T : class { var entityType = typeof(T); var em = EntityMapCache.GetEntityMap(entityType); if (StringHelper.IsNullOrEmptyOrBlankString(tableAlias) && em != null && em.Table != null) { tableAlias = em.Table.TableName; } var whereFields = em.PropertyMapList.Where(p => p.Column != null && p.Column.IsPrimaryKey == true).ToList <PropertyMap>(); List <DbParameter> pList = new List <DbParameter>(); List <string> fc = new List <string>(); foreach (var wp in whereFields) { var wName = wp.Column != null ? wp.Column.ColumnName : wp.Property.PropertyName; fc.Add(wName); var p = this.DataProvider.GenerateParam(wp.Property.GetValue(entity), wName); if (p != null && !pList.Contains(p)) { pList.Add(p); } } ITableDeleteCommand command = new TableDeleteCommand(); command.CommandTextDelete = this.DataProvider.TableCommandGenerator.Delete(tableAlias); command.CommandText_Where = this.DataProvider.TableCommandGenerator.Where(fc.ToArray()); var commandText = this.DataProvider.TableCommandGenerator.CommandText(command); try { this.DataProvider.ExecuteNonQuery(connectionString, CommandType.Text, commandText, pList.ToArray()); return(new TableActionResult()); } catch (Exception ex) { return(new TableActionResult(ex.Message)); } }