public string GetForiegnKeyNameByCollectionProperty(DynamicEntityMetadata dynamicEntityMetadata, string typeName, DynamicCollectionEntityPropertyMetadata dynamicCollectionEntityPropertyMetadata) { if (dynamicCollectionEntityPropertyMetadata.InverseProperty == null) { var complexProperties = dynamicEntityMetadata.DynamicPropertyMetadatas.Where(x => x.TypeName() == typeName).ToList(); if (complexProperties.Count == 1) { return(_namingConventionManager.GetForiegnKeyByComplexProperty(dynamicEntityMetadata.TypeName(), complexProperties.First().PropertyName())); } if (complexProperties.Count == 0) { throw new Exception("GetForiegnKeyNameByCollectionProperty could not find complex property for " + dynamicCollectionEntityPropertyMetadata.PropertyName() + " inside " + typeName); } else { throw new Exception("GetForiegnKeyNameByCollectionProperty could not find complex property for " + dynamicCollectionEntityPropertyMetadata.PropertyName() + " because two or more " + typeName + " exists"); } } else { var fkName = _namingConventionManager.GetForiegnKeyByComplexProperty(dynamicEntityMetadata.TypeName(), dynamicCollectionEntityPropertyMetadata.InverseProperty); if (dynamicEntityMetadata.DynamicPropertyMetadatas.All(x => x.PropertyName() != fkName)) { throw new Exception("GetForiegnKeyNameByCollectionProperty could not find inverse property for " + dynamicCollectionEntityPropertyMetadata.InverseProperty); } return(fkName); } }
public void Fixup(IEnumerable <DynamicEntityMetadata> dynamicEntityMetadatas) { foreach (var dynamicEntityMetadata in dynamicEntityMetadatas) { foreach (var dynamicProperty in dynamicEntityMetadata.DynamicPropertyMetadatas.OfType <DynamicForiegnKeyPropertyMetadata>()) { dynamicProperty.ComplexEntityPropertyMetadata = dynamicEntityMetadata.DynamicPropertyMetadatas.Single(x => x.IsDynamicEntity() && _namingConventionManager.GetForiegnKeyByComplexProperty(dynamicEntityMetadata.TypeName(), x.PropertyName()) == dynamicProperty.PropertyName()); } foreach (var dynamicProperty in dynamicEntityMetadata.DynamicPropertyMetadatas.OfType <DynamicForiegnKeyPropertyMetadata>()) { dynamicProperty.ComplexDynamicEntityMetadata = dynamicEntityMetadatas.Single(x => x.TypeName() == dynamicProperty.ComplexEntityPropertyMetadata.TypeName()); } } }