private static IMemberMapping[] GetReferencedMembers(string names, string sourceName, EntityMapping entity) { return(names.Split(separators).Select(n => GetReferencedMember(n, sourceName, entity)).ToArray()); }
private static IMemberMapping GetReferencedMember(string name, string sourceName, EntityMapping entity) { var mm = entity.GetMappingMember(name); if (mm == null) { throw new InvalidOperationException(string.Format(Res.AttrbuteMappingError, entity.entityType.Name, name, sourceName, entity.entityType.Name)); } return(mm); }
/// <summary> /// 初始化约定映射 /// </summary> /// <param name="isEnumerableType"></param> private void InitializeConversionMapping(bool isEnumerableType) { if (!isEnumerableType) { var underlyingType = memberType; if (underlyingType.IsNullable()) { underlyingType = Nullable.GetUnderlyingType(underlyingType); } if (underlyingType.IsEnum) { underlyingType = Enum.GetUnderlyingType(underlyingType); } if (Converter.IsPrimitiveType(underlyingType) || memberType == typeof(byte[])) { isColumn = true; columnName = MappingConversion.Current.ColumnName(member.Name); bool required = false; int length = 0; sqlType = SqlType.Get(underlyingType); isUpdatable = true; if (EFDataAnnotiationAdapter.Instance != null) { PopulateEFDataAnnotitions(); } if (DataAnnotationMappingAdapter.Instance != null) { object attr = null; #if !SDK35 attr = member.GetCustomAttributes(DataAnnotationMappingAdapter.KeyAttributeType, false).FirstOrDefault(); isPrimaryKey = attr != null; #endif attr = member.GetCustomAttributes(DataAnnotationMappingAdapter.RequiredAttributeType, false).FirstOrDefault(); required = attr != null; attr = member.GetCustomAttributes(DataAnnotationMappingAdapter.StringLengthAttributeType, false).FirstOrDefault(); if (attr != null) { length = (int)DataAnnotationMappingAdapter.Instance.StringLength.Length(attr); } } sqlType = SqlType.Get(underlyingType, new ColumnAttribute { IsNullable = !required, Length = length }); } else//manyToOne { isRelationship = true; relatedEntityType = underlyingType; isManyToOne = isRelationship && !isEnumerableType; if (relatedEntityType == entity.entityType) { relatedEntity = entity; } if (DataAnnotationMappingAdapter.Instance != null) { #if !SDK35 var assAtt = member.GetCustomAttributes(DataAnnotationMappingAdapter.AssociationAttributeType, false).FirstOrDefault(); if (assAtt != null) { thisKey = DataAnnotationMappingAdapter.Instance.Association.ThisKey(assAtt) as string; otherKey = DataAnnotationMappingAdapter.Instance.Association.OtherKey(assAtt) as string; } #endif } } } else { isRelationship = true; relatedEntityType = ReflectionHelper.GetElementType(memberType); isManyToOne = isRelationship && !isEnumerableType; if (relatedEntityType == entity.entityType) { relatedEntity = entity; } if (DataAnnotationMappingAdapter.Instance != null) { #if !SDK35 var assAtt = member.GetCustomAttributes(DataAnnotationMappingAdapter.AssociationAttributeType, false).FirstOrDefault(); if (assAtt != null) { thisKey = DataAnnotationMappingAdapter.Instance.Association.ThisKey(assAtt) as string; otherKey = DataAnnotationMappingAdapter.Instance.Association.OtherKey(assAtt) as string; } #endif } } }