public PrimitiveListTable(PropertyMapping parentIdColumn, SqlType primitiveType, bool maintainOrder = false) { if (parentIdColumn == null) throw new ArgumentNullException("parentIdColumn"); if (primitiveType == null) throw new ArgumentNullException("primitiveType"); _columns = new List<PropertyMapping>(3) { new PropertyMapping { ColumnName = "ParentId", SqlType = parentIdColumn.SqlType, Table = this }, new PropertyMapping { ColumnName = "Value", SqlType = primitiveType, Table = this } }; if (maintainOrder) { _columns.Add(new PropertyMapping { ColumnName = "Index", SqlType = new SqlType(SqlDbType.BigInt, false), Table = this }); } MaintainOrder = maintainOrder; }
public void AddProperty(PropertyMapping propertyMapping) { _propertyMappings.Add(propertyMapping); }
private void GenerateForPrimitive(Type type, PropertyMapping prop, ILGenerator generator, int i) { var propertyInfo = type.GetProperty(prop.Name); if (propertyInfo == null) throw new InvalidOperationException("Class does not match mapping. This is really strange."); var propertyType = propertyInfo.PropertyType; var canBeNull = prop.Nullable || propertyType == typeof (string); var setMethod = propertyInfo.GetSetMethod(); if (setMethod == null) throw new InvalidOperationException("Mapped property must have set method."); var endIfLabel = generator.DefineLabel(); if (canBeNull) { // if(!reader.IsDbNull(i + offset)) generator.Emit(OpCodes.Ldarg_0); generator.Emit(OpCodes.Ldarg_2); generator.Emit(OpCodes.Ldc_I4, i); generator.Emit(OpCodes.Add); generator.Emit(OpCodes.Callvirt, IsDbNullMethod); generator.Emit(OpCodes.Brtrue, endIfLabel); } // obj.Property = reader.GetInt(i + offset); generator.Emit(OpCodes.Ldarg_1); generator.Emit(OpCodes.Ldarg_0); generator.Emit(OpCodes.Ldarg_2); generator.Emit(OpCodes.Ldc_I4, i); generator.Emit(OpCodes.Add); generator.Emit(OpCodes.Call, GetGetterMethod(propertyType, prop.Nullable)); if (prop.Nullable) { // obj.Property = new Nullable<int>(reader.GetInt(i + offset)); generator.Emit(OpCodes.Newobj, propertyType.GetConstructor(propertyType.GetGenericArguments())); } generator.Emit(OpCodes.Call, setMethod); // end if if (canBeNull) generator.MarkLabel(endIfLabel); }