private void ProcessOne2Many() { foreach (EntityDefinition e_ in Model.GetEntities()) { EntityDefinition e = e_; foreach (EntityDefinition oe_ in from k in Model.GetActiveEntities() where /*k != e && */ !e.One2ManyRelations.Any(item => !item.Disabled && item.Entity.Identifier == k.Identifier) select k) { EntityDefinition oe = oe_; var entityProps = oe.GetActiveProperties() .Where(item => item.PropertyType.IsEntityType && item.PropertyType.Entity.Identifier == e.Identifier) .Cast <EntityPropertyDefinition>(); int idx = 1; foreach (EntityPropertyDefinition pd in entityProps) { int cnt = Model.GetActiveRelations().OfType <RelationDefinition>().Count(r => (r.Left.Entity.Identifier == oe.Identifier && r.Right.Entity.Identifier == e.Identifier) || (r.Left.Entity.Identifier == e.Identifier && r.Right.Entity.Identifier == oe.Identifier)); string accName = null; string prop = null; if (cnt > 0 || entityProps.Count() > 1) { accName = WXMLCodeDomGeneratorNameHelper.GetMultipleForm(oe.Name + idx); prop = pd.Name; } e.AddEntityRelations(new EntityRelationDefinition() { Entity = oe, SourceEntity = e, AccessorName = accName, PropertyAlias = prop, }); idx++; } } } }