/// <summary> /// Initialises a new instance of the <see cref="PocoObjectInfo" /> class. /// </summary> /// <param name="forType">The type the object info relates to.</param> /// <param name="tableInfo">The table info.</param> /// <exception cref="ArgumentNullException"> /// Thrown if forType or tableInfo are null. /// </exception> public PocoObjectInfo(Type forType, TableInfo tableInfo) { if (forType == null) { throw new ArgumentNullException("forType"); } if (tableInfo == null) { throw new ArgumentNullException("tableInfo"); } this.forType = forType; this.tableInfo = tableInfo; if (this.tableInfo.IdentifierColumn != null && this.tableInfo.IdentifierColumn.PropertyInfo.PropertyType.IsValueType) { this.defaultIdentifierValue = (ValueType)Activator.CreateInstance(this.tableInfo.IdentifierColumn.PropertyInfo.PropertyType); } if (this.tableInfo.IdentifierColumn != null) { this.getIdentifierValue = DelegateFactory.CreateGetIdentifier(this); this.getInsertValues = DelegateFactory.CreateGetInsertValues(this); this.getUpdateValues = DelegateFactory.CreateGetUpdateValues(this); this.setIdentifierValue = DelegateFactory.CreateSetIdentifier(this); } this.instanceFactory = DelegateFactory.CreateInstanceFactory(this); }
public IObjectInfo CreateObjectInfo(Type forType) { if (forType == null) { throw new ArgumentNullException("forType"); } var tableAttribute = forType.GetAttribute<TableAttribute>(inherit: false); if (tableAttribute == null) { throw new MappingException(ExceptionMessages.AttributeMappingConvention_NoTableAttribute.FormatWith(forType.FullName)); } var identifierStrategy = IdentifierStrategy.DbGenerated; var columns = this.CreateColumnInfos(forType, ref identifierStrategy); var tableInfo = new TableInfo(columns, identifierStrategy, tableAttribute.Name, tableAttribute.Schema); if (this.log.IsDebug) { this.log.Debug(LogMessages.MappingConvention_MappingTypeToTable, forType.FullName, tableInfo.Schema, tableInfo.Name); } return new PocoObjectInfo(forType, tableInfo); }
public void ConstructorSetsPropertyValuesWithoutIdentifierMapped() { var columns = new ReadOnlyCollection<ColumnInfo>(new[] { new ColumnInfo("Name", typeof(Customer).GetProperty("Name"), false, true, true), new ColumnInfo("Created", typeof(Customer).GetProperty("Created"), false, true, false), new ColumnInfo("Updated", typeof(Customer).GetProperty("Updated"), false, false, true) }); var identifierStrategy = IdentifierStrategy.Assigned; var name = "Customers"; var schema = "Sales"; var tableInfo = new TableInfo(columns, identifierStrategy, name, schema); Assert.Equal(columns, tableInfo.Columns); Assert.Null(tableInfo.IdentifierColumn); Assert.Equal(identifierStrategy, tableInfo.IdentifierStrategy); Assert.Equal(name, tableInfo.Name); Assert.Equal(schema, tableInfo.Schema); Assert.Equal(2, tableInfo.InsertColumnCount); Assert.Equal(2, tableInfo.UpdateColumnCount); }
public IObjectInfo CreateObjectInfo(Type forType) { if (forType == null) { throw new ArgumentNullException("forType"); } var identifierStrategy = this.settings.ResolveIdentifierStrategy(forType); var columns = this.CreateColumnInfos(forType, identifierStrategy); var tableInfo = new TableInfo( columns, identifierStrategy, this.settings.ResolveTableName(forType), this.settings.ResolveTableSchema(forType)); if (this.log.IsDebug) { this.log.Debug(LogMessages.MappingConvention_MappingTypeToTable, forType.FullName, tableInfo.Schema, tableInfo.Name); } return new PocoObjectInfo(forType, tableInfo); }