public bool Equals(T x, T y) { var leftValue = _conventionReader.GetPrimaryKeyValue(x); var rightValue = _conventionReader.GetPrimaryKeyValue(y); // If the id of both entities is null we can't really say if they represent the same entity // or not, so treat them as different objects. Better to have duplicates than missing rows in // the result set, which would be the result of incorrectly assuming two rows of representing // the same entity. return(Equals(leftValue, rightValue) && leftValue != null); }
public void Delete <T>(T instance) { var tableName = _conventionReader.GetTableName <T>(); var primaryKeyColumnName = _conventionReader.GetPrimaryKeyColumnName <T>(); var primaryKeyValue = _conventionReader.GetPrimaryKeyValue(instance); var constraintExpression = QueryExpression.Create(new EqualsExpression(primaryKeyColumnName, primaryKeyValue)); var command = _sqlGenerator.CreateDeleteCommand(tableName, constraintExpression); _dbCommandExecutor.ExecuteNonQuery(command, ConnectionString); }
private Row GetRowForEntity(object instance) { var type = instance.GetType(); var table = Table(type); var primaryKeyColumnName = ConventionReader.GetPrimaryKeyColumnName(type); var primaryKeyValue = ConventionReader.GetPrimaryKeyValue(instance); foreach (var row in table.Rows) { var columnValue = row.GetColumnValue(primaryKeyColumnName); if (columnValue != null && columnValue.MatchesValue(primaryKeyValue)) { return(row); } } throw new WeenyMapperException("Could not find any entity of type '{0}' with the primary key '{1}' with value '{2}'", type.FullName, primaryKeyColumnName, primaryKeyValue); }