/// <summary> /// Adds the table of the given type to the mappings. /// </summary> /// <remarks> /// The given type must have a <see cref="TableAttribute" /> to be mappable. /// </remarks> /// <param name="tableType">Type of the table.</param> /// <returns> /// Returns the <see cref="MetaTable"/> for the given table type or null if it is not mappable. /// </returns> private MetaTable AddTableType(Type tableType) { //No need to check base types because framework implementation doesn't do this either var tableAttribute = tableType.GetAttribute <TableAttribute>(); if (tableAttribute == null) { return(null); } //First set up the table without associations var metaType = new AttributedMetaType(tableType); var metaTable = new AttributedMetaTable(tableAttribute, metaType, this); metaType.SetMetaTable(metaTable); _Tables[tableType] = metaTable; return(metaTable); }
public AttributedMetaAssociation(MemberInfo member, AssociationAttribute attribute, MetaDataMember metaDataMember) { _memberInfo = member; _associationAttribute = attribute; _thisMember = metaDataMember; // The bug described here: // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=376669 // says that under certain conditions, there's a bug where _otherMember == _thisMember // Not only is there no point in reproducing a MS bug, it's not as simple as simply setting _otherMember = metaDataMember Type otherType = _memberInfo.GetFirstInnerReturnType(); string associationName = member.GetAttribute <AssociationAttribute>().Name; AttributedMetaType ownedMetaType = metaDataMember.DeclaringType.Model.GetMetaType(otherType) as AttributedMetaType; if (ownedMetaType == null) { throw new InvalidOperationException("Key in referenced table is of a different SQL MetaData provider"); } _otherMember = ownedMetaType.AssociationsLookup[otherType.GetMembers().Where(m => (AttributeNameNullCheck(m.GetAttribute <AssociationAttribute>()) == associationName) && (m != member)).Single()]; }