public static EntityMapping <TEntity> Association <TEntity, TEntity1>(this EntityMapping <TEntity> entityMapping, Expression <Func <TEntity, TEntity1> > predicate, AssociationAttribute association) where TEntity : class where TEntity1 : class { var mi = GetMember(predicate); if (mi.DeclaringType != typeof(TEntity) && !typeof(TEntity).IsSubclassOf(mi.DeclaringType)) { throw Error.MappedMemberHadNoCorrespondingMemberInType(mi.Name, typeof(TEntity).Name); } entityMapping.Add(mi, association); return(entityMapping); }
// Methods internal AttributedMetaAssociation(AttributedMetaDataMember member, AssociationAttribute attr) { this.attributeProvider = member.MetaModel.AttributeProvider; this.thisMember = member; this.isMany = TypeSystem.IsSequenceType(thisMember.Type); Type type = this.isMany ? TypeSystem.GetElementType(thisMember.Type) : thisMember.Type; this.otherType = this.thisMember.DeclaringType.Model.GetMetaType(type); this.thisKey = (attr.ThisKey != null) ? MakeKeys(thisMember.DeclaringType, attr.ThisKey) : thisMember.DeclaringType.IdentityMembers; this.otherKey = (attr.OtherKey != null) ? MakeKeys(otherType, attr.OtherKey) : this.otherType.IdentityMembers; this.thisKeyIsPrimaryKey = AreEqual(this.thisKey, thisMember.DeclaringType.IdentityMembers); this.otherKeyIsPrimaryKey = AreEqual(this.otherKey, otherType.IdentityMembers); this.isForeignKey = attr.IsForeignKey; this.isUnique = attr.IsUnique; this.deleteRule = attr.DeleteRule; this.deleteOnNull = attr.DeleteOnNull; foreach (MetaDataMember member2 in this.thisKey) { if (!member2.CanBeNull) { this.isNullable = false; break; } } if (this.deleteOnNull && ((!this.isForeignKey || this.isMany) || this.isNullable)) { throw Mapping.Error.InvalidDeleteOnNullSpecification(member); } if (((this.thisKey.Count != this.otherKey.Count) && (this.thisKey.Count > 0)) && (this.otherKey.Count > 0)) { throw Mapping.Error.MismatchedThisKeyOtherKey(member.Name, member.DeclaringType.Name); } foreach (MetaDataMember member3 in this.otherType.PersistentDataMembers) { /* var customAttribute = (AssociationAttribute)Attribute.GetCustomAttribute(member3.Member, typeof(AssociationAttribute)); */ var customAttribute = this.attributeProvider.GetAssociationAttribute(member3.Member); if (((customAttribute != null) && (member3 != this.thisMember)) && (customAttribute.Name == attr.Name)) { this.otherMember = member3; break; } } }
// Methods internal AttributedMetaDataMember(AttributedMetaType metaType, MemberInfo mi, int ordinal) { this.declaringType = mi.DeclaringType; this.metaType = metaType; this.member = mi; this.ordinal = ordinal; this.type = TypeSystem.GetMemberType(mi); this.isNullableType = TypeSystem.IsNullableType(this.type); this.attributeProvider = this.MetaModel.AttributeProvider; /* * this.attrColumn = (ColumnAttribute)Attribute.GetCustomAttribute(mi, typeof(ColumnAttribute)); * this.attrAssoc = (AssociationAttribute)Attribute.GetCustomAttribute(mi, typeof(AssociationAttribute)); */ this.attrColumn = attributeProvider.GetColumnAttribute(mi); this.attrAssoc = attributeProvider.GetAssociationAttribute(mi); this.attr = (this.attrColumn != null) ? ((DataAttribute)attrColumn) : this.attrAssoc; if (attr != null && attr.Storage != null) { MemberInfo[] member = mi.DeclaringType.GetMember(this.attr.Storage, BindingFlags.NonPublic | BindingFlags.Instance); if (member == null || member.Length != 1) { throw Mapping.Error.BadStorageProperty(this.attr.Storage, mi.DeclaringType, mi.Name); } this.storageMember = member[0]; } Type entityType = (this.storageMember != null) ? TypeSystem.GetMemberType(this.storageMember) : this.type; this.isDeferred = this.IsDeferredType(entityType); if ((this.attrColumn != null && this.attrColumn.IsDbGenerated) && (this.attrColumn.IsPrimaryKey && this.attrColumn.AutoSync != AutoSync.Default) && (this.attrColumn.AutoSync != AutoSync.OnInsert)) { throw Mapping.Error.IncorrectAutoSyncSpecification(mi.Name); } }
public static AssociationAttribute Keys(this AssociationAttribute association, string thisKey, string otherKey) { association.ThisKey = thisKey; association.OtherKey = otherKey; return(association); }
public static AssociationAttribute ForeignKey(this AssociationAttribute association) { association.IsForeignKey = true; return(association); }
public static AssociationAttribute DeleteOnNull(this AssociationAttribute association) { association.DeleteOnNull = true; return(association); }
public void Add(MemberInfo mi, AssociationAttribute association) { associations[mi] = association; }