public void Update <T>(T instance) { var tableName = _conventionReader.GetTableName <T>(); var columnValues = _conventionReader.GetColumnValuesForInsertOrUpdate(instance); var primaryKeyColumn = _conventionReader.GetPrimaryKeyColumnName <T>(); var primaryKeyValue = _conventionReader.GetPrimaryKeyValue(instance); var constraintExpression = QueryExpression.Create(new EqualsExpression(primaryKeyColumn, primaryKeyValue)); var command = _sqlGenerator.CreateUpdateCommand(tableName, constraintExpression, columnValues); _dbCommandExecutor.ExecuteNonQuery(command, ConnectionString); }
public void AddJoin(ObjectSubQueryJoin joinSpecification, string childAlias, string parentAlias) { EnsureSubQuery(childAlias, joinSpecification.ChildType); EnsureSubQuery(parentAlias, joinSpecification.ParentType); string manyToOneForeignKeyColumnName; if (joinSpecification.HasChildProperty) { manyToOneForeignKeyColumnName = _conventionReader.GetManyToOneForeignKeyColumnName(joinSpecification.ChildProperty); } else { manyToOneForeignKeyColumnName = _conventionReader.GetColumnName(joinSpecification.ChildToParentForeignKeyProperty); } var joinSpec = new SqlSubQueryJoin { ChildTableName = _conventionReader.GetTableName(joinSpecification.ChildType), ParentTableName = _conventionReader.GetTableName(joinSpecification.ParentType), ChildForeignKeyColumnName = manyToOneForeignKeyColumnName, ParentPrimaryKeyColumnName = _conventionReader.GetPrimaryKeyColumnName(joinSpecification.ParentType), }; AddJoin(joinSpec, childAlias, parentAlias); ObjectRelations.Add(ObjectRelation.Create(joinSpecification, childAlias, parentAlias)); }
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); }