internal MappedAssociation(MappedDataMember mm, AssociationMapping assocMap) { this.thisMember = mm; this.assocMap = assocMap; this.Init(); this.InitOther(); //validate the number of ThisKey columns is the same as the number of OtherKey columns if (this.thisKey.Count != this.otherKey.Count && this.thisKey.Count > 0 && this.otherKey.Count > 0) { throw Error.MismatchedThisKeyOtherKey(thisMember.Name, thisMember.DeclaringType.Name); } }
internal MappedAssociation(MappedDataMember mm, AssociationMapping assocMap) { this.thisMember = mm; this.assocMap = assocMap; this.Init(); this.InitOther(); //validate the number of ThisKey columns is the same as the number of OtherKey columns if(this.thisKey.Count != this.otherKey.Count && this.thisKey.Count > 0 && this.otherKey.Count > 0) { throw Error.MismatchedThisKeyOtherKey(thisMember.Name, thisMember.DeclaringType.Name); } }
private void InitDataMembers() { if (this.dataMembers == null) { Dictionary <object, MetaDataMember> map = new Dictionary <object, MetaDataMember>(); List <MetaDataMember> dMembers = new List <MetaDataMember>(); int ordinal = 0; BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; // Map of valid mapped names. Dictionary <string, MemberMapping> names = new Dictionary <string, MemberMapping>(); Type currentType = this.type; for (TypeMapping tm = this.typeMapping; tm != null; tm = tm.BaseType) { foreach (MemberMapping mmap in tm.Members) { names[mmap.MemberName + ":" + currentType.Name] = mmap; } currentType = currentType.BaseType; } HashSet <string> namesSeen = new HashSet <string>(); // Keep track of which names from the mapping file have been seen. FieldInfo[] fis = TypeSystem.GetAllFields(this.type, flags).ToArray(); if (fis != null) { foreach (FieldInfo fi in fis) { MemberMapping mmap; string name = fi.Name + ":" + fi.DeclaringType.Name; if (names.TryGetValue(name, out mmap)) { namesSeen.Add(name); object dn = InheritanceRules.DistinguishedMemberName(fi); MetaDataMember mm; if (!map.TryGetValue(dn, out mm)) { mm = new MappedDataMember(this, fi, mmap, ordinal); map.Add(InheritanceRules.DistinguishedMemberName(mm.Member), mm); dMembers.Add(mm); this.InitSpecialMember(mm); } ValidatePrimaryKeyMember(mm); ordinal++; } } } PropertyInfo[] pis = TypeSystem.GetAllProperties(this.type, flags).ToArray(); if (pis != null) { foreach (PropertyInfo pi in pis) { MemberMapping mmap; string name = pi.Name + ":" + pi.DeclaringType.Name; if (names.TryGetValue(name, out mmap)) { namesSeen.Add(name); MetaDataMember mm; object dn = InheritanceRules.DistinguishedMemberName(pi); if (!map.TryGetValue(dn, out mm)) { mm = new MappedDataMember(this, pi, mmap, ordinal); map.Add(InheritanceRules.DistinguishedMemberName(mm.Member), mm); dMembers.Add(mm); this.InitSpecialMember(mm); } ValidatePrimaryKeyMember(mm); ordinal++; } } } this.dataMembers = dMembers.AsReadOnly(); this.dataMemberMap = map; // Finally, make sure that all types in the mapping file were consumed. foreach (string name in namesSeen) { names.Remove(name); } foreach (var orphan in names) { Type aboveRoot = inheritanceRoot.Type.BaseType; while (aboveRoot != null) { foreach (MemberInfo mi in aboveRoot.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (String.Compare(mi.Name, orphan.Value.MemberName, StringComparison.Ordinal) == 0) { throw Error.MappedMemberHadNoCorrespondingMemberInType(orphan.Value.MemberName, type.Name); } } aboveRoot = aboveRoot.BaseType; } } } }
private void InitDataMembers() { if (this.dataMembers == null) { Dictionary<object, MetaDataMember> map = new Dictionary<object, MetaDataMember>(); List<MetaDataMember> dMembers = new List<MetaDataMember>(); int ordinal = 0; BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; // Map of valid mapped names. Dictionary<string, MemberMapping> names = new Dictionary<string, MemberMapping>(); Type currentType = this.type; for (TypeMapping tm = this.typeMapping; tm != null; tm = tm.BaseType) { foreach (MemberMapping mmap in tm.Members) { names[mmap.MemberName + ":" + currentType.Name] = mmap; } currentType = currentType.BaseType; } HashSet<string> namesSeen = new HashSet<string>(); // Keep track of which names from the mapping file have been seen. FieldInfo[] fis = TypeSystem.GetAllFields(this.type, flags).ToArray(); if (fis != null) { foreach (FieldInfo fi in fis) { MemberMapping mmap; string name = fi.Name + ":" + fi.DeclaringType.Name; if (names.TryGetValue(name, out mmap)) { namesSeen.Add(name); object dn = InheritanceRules.DistinguishedMemberName(fi); MetaDataMember mm; if (!map.TryGetValue(dn, out mm)) { mm = new MappedDataMember(this, fi, mmap, ordinal); map.Add(InheritanceRules.DistinguishedMemberName(mm.Member), mm); dMembers.Add(mm); this.InitSpecialMember(mm); } ValidatePrimaryKeyMember(mm); ordinal++; } } } PropertyInfo[] pis = TypeSystem.GetAllProperties(this.type, flags).ToArray(); if (pis != null) { foreach (PropertyInfo pi in pis) { MemberMapping mmap; string name = pi.Name + ":" + pi.DeclaringType.Name; if (names.TryGetValue(name, out mmap)) { namesSeen.Add(name); MetaDataMember mm; object dn = InheritanceRules.DistinguishedMemberName(pi); if (!map.TryGetValue(dn, out mm)) { mm = new MappedDataMember(this, pi, mmap, ordinal); map.Add(InheritanceRules.DistinguishedMemberName(mm.Member), mm); dMembers.Add(mm); this.InitSpecialMember(mm); } ValidatePrimaryKeyMember(mm); ordinal++; } } } this.dataMembers = dMembers.AsReadOnly(); this.dataMemberMap = map; // Finally, make sure that all types in the mapping file were consumed. foreach(string name in namesSeen) { names.Remove(name); } foreach(var orphan in names) { Type aboveRoot = inheritanceRoot.Type.BaseType; while (aboveRoot!=null) { foreach(MemberInfo mi in aboveRoot.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if(String.Compare(mi.Name, orphan.Value.MemberName, StringComparison.Ordinal)==0) { throw Error.MappedMemberHadNoCorrespondingMemberInType(orphan.Value.MemberName, type.Name); } } aboveRoot = aboveRoot.BaseType; } } } }