private List <ModelUnidirectionalAssociation> GetUnidirectionalAssociations(IEntityType entityType) { List <ModelUnidirectionalAssociation> result = new List <ModelUnidirectionalAssociation>(); foreach (INavigation navigationProperty in entityType.GetDeclaredNavigations().Where(n => n.FindInverse() == null)) { ModelUnidirectionalAssociation association = new ModelUnidirectionalAssociation(); association.SourceClassName = navigationProperty.DeclaringType.ClrType.Name; association.SourceClassNamespace = navigationProperty.DeclaringType.ClrType.Namespace; Type targetType = navigationProperty.GetTargetType().ClrType.Unwrap(); association.TargetClassName = targetType.Name; association.TargetClassNamespace = targetType.Namespace; // the property in the source class (referencing the target class) association.TargetPropertyTypeName = navigationProperty.PropertyInfo.PropertyType.Unwrap().Name; association.TargetPropertyName = navigationProperty.Name; association.TargetMultiplicity = ConvertMultiplicity(navigationProperty.GetTargetMultiplicity()); // the property in the target class (referencing the source class) association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.GetSourceMultiplicity()); // unfortunately, EFCore doesn't serialize documentation like EF6 did //association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary; //association.TargetDescription = navigationProperty.ToEndMember.Documentation?.LongDescription; //association.SourceSummary = navigationProperty.FromEndMember.Documentation?.Summary; //association.SourceDescription = navigationProperty.FromEndMember.Documentation?.LongDescription; result.Add(association); } return(result); }
private List <ModelUnidirectionalAssociation> GetUnidirectionalAssociations(EntityType entityType) { List <ModelUnidirectionalAssociation> result = new List <ModelUnidirectionalAssociation>(); foreach (NavigationProperty navigationProperty in entityType.DeclaredNavigationProperties.Where(np => Inverse(np) == null)) { // ReSharper disable UseObjectOrCollectionInitializer ModelUnidirectionalAssociation association = new ModelUnidirectionalAssociation(); association.SourceClassName = navigationProperty.DeclaringType.Name; association.SourceClassNamespace = navigationProperty.DeclaringType.NamespaceName; association.TargetClassName = navigationProperty.ToEndMember.GetEntityType().Name; association.TargetClassNamespace = navigationProperty.ToEndMember.GetEntityType().NamespaceName; // the property in the source class (referencing the target class) association.TargetPropertyTypeName = navigationProperty.ToEndMember.GetEntityType().Name; association.TargetPropertyName = navigationProperty.Name; association.TargetMultiplicity = ConvertMultiplicity(navigationProperty.ToEndMember.RelationshipMultiplicity); association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary; association.TargetDescription = navigationProperty.ToEndMember.Documentation?.LongDescription; // the property in the target class (referencing the source class) association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.FromEndMember.RelationshipMultiplicity); // ReSharper restore UseObjectOrCollectionInitializer log.Info($"Found unidirectional association {association.SourceClassName}.{association.TargetPropertyName} -> {association.TargetClassName}"); log.Info("\n " + JsonConvert.SerializeObject(association)); result.Add(association); } return(result); }
private List <ModelUnidirectionalAssociation> GetUnidirectionalAssociations(EntityType entityType) { List <ModelUnidirectionalAssociation> result = new List <ModelUnidirectionalAssociation>(); foreach (NavigationProperty navigationProperty in entityType.DeclaredNavigationProperties.Where(np => Inverse(np) == null)) { ModelUnidirectionalAssociation association = new ModelUnidirectionalAssociation(); association.SourceClassName = navigationProperty.DeclaringType.Name; association.SourceClassNamespace = navigationProperty.DeclaringType.NamespaceName; association.TargetClassName = navigationProperty.ToEndMember.GetEntityType().Name; association.TargetClassNamespace = navigationProperty.ToEndMember.GetEntityType().NamespaceName; // the property in the source class (referencing the target class) association.TargetPropertyTypeName = navigationProperty.ToEndMember.GetEntityType().Name; association.TargetPropertyName = navigationProperty.Name; association.TargetMultiplicity = ConvertMultiplicity(navigationProperty.ToEndMember.RelationshipMultiplicity); association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary; association.TargetDescription = navigationProperty.ToEndMember.Documentation?.LongDescription; // the property in the target class (referencing the source class) association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.FromEndMember.RelationshipMultiplicity); result.Add(association); } return(result); }
private List <ModelUnidirectionalAssociation> GetUnidirectionalAssociations(EntityType entityType) { List <ModelUnidirectionalAssociation> result = new List <ModelUnidirectionalAssociation>(); if (entityType == null) { return(result); } foreach (NavigationProperty navigationProperty in entityType.DeclaredNavigationProperties.Where(np => Inverse(np) == null)) { ModelUnidirectionalAssociation association = new ModelUnidirectionalAssociation(); //StructuralType sourceType = navigationProperty.DeclaringType; EntityType sourceType = navigationProperty.FromEndMember.GetEntityType(); EntityType targetType = navigationProperty.ToEndMember.GetEntityType(); association.SourceClassName = sourceType.Name; association.SourceClassNamespace = sourceType.NamespaceName; association.TargetClassName = targetType.Name; association.TargetClassNamespace = targetType.NamespaceName; // the property in the source class (referencing the target class) association.TargetPropertyTypeName = targetType.Name; association.TargetPropertyName = navigationProperty.Name; association.TargetMultiplicity = ConvertMultiplicity(navigationProperty.ToEndMember.RelationshipMultiplicity); association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary; association.TargetDescription = navigationProperty.ToEndMember.Documentation?.LongDescription; // the property in the target class (referencing the source class) association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.FromEndMember.RelationshipMultiplicity); // look for declared foreign keys List <EdmProperty> dependentProperties = navigationProperty.GetDependentProperties().ToList(); if (dependentProperties.Any()) { association.ForeignKey = string.Join(",", dependentProperties.Select(p => p.Name)); } string json = JsonConvert.SerializeObject(association); log.Debug($"Found unidirectional association {association.SourceClassName}.{association.TargetPropertyName} -> {association.TargetClassName}"); log.Debug("\n " + json); result.Add(association); } return(result); }
private List <ModelUnidirectionalAssociation> GetUnidirectionalAssociations(IEntityType entityType) { List <ModelUnidirectionalAssociation> result = new List <ModelUnidirectionalAssociation>(); foreach (INavigation navigationProperty in entityType.GetDeclaredNavigations().Where(n => n.Inverse == null)) { ModelUnidirectionalAssociation association = new ModelUnidirectionalAssociation(); association.SourceClassName = navigationProperty.DeclaringType.ClrType.Name; association.SourceClassNamespace = navigationProperty.DeclaringType.ClrType.Namespace; Type targetType = navigationProperty.TargetEntityType.ClrType.Unwrap(); association.TargetClassName = targetType.Name; association.TargetClassNamespace = targetType.Namespace; // the property in the source class (referencing the target class) association.TargetPropertyTypeName = navigationProperty.PropertyInfo.PropertyType.Unwrap().Name; association.TargetPropertyName = navigationProperty.Name; association.TargetMultiplicity = ConvertMultiplicity(navigationProperty.GetTargetMultiplicity()); // the property in the target class (referencing the source class) association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.GetSourceMultiplicity()); if (navigationProperty.ForeignKey != null) { List <string> fkPropertyDeclarations = navigationProperty.ForeignKey.Properties .Where(p => !p.IsShadowProperty()) .Select(p => p.Name) .ToList(); association.ForeignKey = fkPropertyDeclarations.Any() ? string.Join(",", fkPropertyDeclarations) : null; } // unfortunately, EFCore doesn't serialize documentation like EF6 did //association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary; //association.TargetDescription = navigationProperty.ToEndMember.Documentation?.LongDescription; //association.SourceSummary = navigationProperty.FromEndMember.Documentation?.Summary; //association.SourceDescription = navigationProperty.FromEndMember.Documentation?.LongDescription; result.Add(association); } return(result); }