internal MemberMapping(MemberInfo member, MemberAttribute attribute, EntityMapping entity) { this.member = member; this.entity = entity; memberType = member.GetMemberType(); var isEnumerableType = memberType != Types.String && memberType != typeof(byte[]) && Types.IEnumerable.IsAssignableFrom(memberType); if (attribute == null) { InitializeConversionMapping(isEnumerableType); } else InitializeAttributeMapping(attribute, isEnumerableType); getter = member.GetGetter(); if (storageMember != null) setter = storageMember.GetSetter(); else setter = member.GetSetter(); if (columnName == null) columnName = member.Name; }
public ColumnModel(MemberInfo member) { MemberType = member.GetMemberType(); var sourceType = MemberType; AllowDBNull = sourceType.IsNullable(); if (!AllowDBNull) { IsEnum = sourceType.IsEnum; if (IsEnum) DataType = Enum.GetUnderlyingType(sourceType); else DataType = sourceType; } else { sourceType = Nullable.GetUnderlyingType(sourceType); IsEnum = sourceType.IsEnum; if (IsEnum) DataType = Enum.GetUnderlyingType(sourceType); else DataType = sourceType; } ColumnName = member.Name; var getter = member.GetGetter(); if (AllowDBNull) { var p = MemberType.GetProperty("Value"); if (IsEnum) { SetColumnValue = (entity, row) => { var v = getter(entity); if (v == null) row[ColumnName] = DBNull.Value; else row[ColumnName] = Converter.Convert(p.GetValue(v, null), DataType); }; } else { SetColumnValue = (entity, row) => { var v = getter(entity); if (v == null) row[ColumnName] = DBNull.Value; else row[ColumnName] = p.GetValue(v, null); }; } } else { if (DataType == Types.String) { AllowDBNull = true; SetColumnValue = (entity, row) => { var v = getter(entity); row[ColumnName] = v == null ? DBNull.Value : v; }; } else { if(IsEnum) SetColumnValue = (entity, row) => row[ColumnName] = Converter.Convert(getter(entity),DataType); else SetColumnValue = (entity, row) => row[ColumnName] = getter(entity); } } }