Skip to content

Commit

Permalink
WIP fk column names
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sawczyn committed Jan 29, 2024
1 parent 082641c commit 2a31fda
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 80 deletions.
4 changes: 2 additions & 2 deletions dist/Sawczyn.EFDesigner.EFModel.DslPackage.vsix
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes)
propertyDescriptors.Remove("TargetRole");
}

if (association.SourceMultiplicity != Multiplicity.ZeroMany || association.TargetMultiplicity != Multiplicity.ZeroMany)
{
propertyDescriptors.Remove("SourceRole");
propertyDescriptors.Remove("TargetRole");
}

// only display delete behavior on the principal end
// except that owned types don't have deletion behavior choices
if (association.SourceRole != EndpointRole.Principal || association.Source.IsDependentType || association.Target.IsDependentType)
Expand Down
8 changes: 4 additions & 4 deletions src/Dsl/DslDefinition.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@
<ExternalTypeMoniker Name="/System/Boolean" />
</Type>
</DomainProperty>
<DomainProperty Id="33c1f80e-1661-4666-9112-918463abc4ec" Description="Optional name of column holding foreign key value for this end of the association" Name="FKColumnName" DisplayName="Foreign Key Column Name" Category="Database">
<DomainProperty Id="33c1f80e-1661-4666-9112-918463abc4ec" Description="Optional name of column holding foreign key value for this end of the association" Name="TargetFKColumnName" DisplayName="Foreign Key Column Name" Category="End 2">
<Type>
<ExternalTypeMoniker Name="/System/String" />
</Type>
Expand Down Expand Up @@ -1623,7 +1623,7 @@
<ExternalTypeMoniker Name="/System/Boolean" />
</Type>
</DomainProperty>
<DomainProperty Id="695d0645-c6d9-416a-bc18-7967f8339ced" Description="Optional name of column holding foreign key value for this end of the association" Name="SourceFKColumnName" DisplayName="End1 Foreign Key Column Name" Category="Database">
<DomainProperty Id="695d0645-c6d9-416a-bc18-7967f8339ced" Description="Optional name of column holding foreign key value for this end of the association" Name="SourceFKColumnName" DisplayName="End1 Foreign Key Column Name" Category="End 1">
<Type>
<ExternalTypeMoniker Name="/System/String" />
</Type>
Expand Down Expand Up @@ -2336,8 +2336,8 @@
<XmlPropertyData XmlName="isJSON">
<DomainPropertyMoniker Name="Association/IsJSON" />
</XmlPropertyData>
<XmlPropertyData XmlName="fKColumnName">
<DomainPropertyMoniker Name="Association/FKColumnName" />
<XmlPropertyData XmlName="targetFKColumnName">
<DomainPropertyMoniker Name="Association/TargetFKColumnName" />
</XmlPropertyData>
</ElementData>
</XmlClassData>
Expand Down
114 changes: 57 additions & 57 deletions src/Dsl/DslDefinition.dsl.diagram

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions src/Utilities/EFCore5Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,36 @@ protected List<ModelUnidirectionalAssociation> GetUnidirectionalAssociations(IEn
// the property in the target class (referencing the source class)
association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.GetSourceMultiplicity());

List<string> fkPropertyDeclarations = navigationProperty.ForeignKey.Properties
List<string> fkPropertyNames = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.Name)
.ToList();
.Select(p => p.Name)
.ToList();

association.ForeignKey = fkPropertyDeclarations.Any()
? string.Join(",", fkPropertyDeclarations)
association.ForeignKey = fkPropertyNames.Any()
? string.Join(",", fkPropertyNames)
: null;

List<string> fkColumnNames = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.GetColumnName())
.ToList();
association.ForeignKeyColumnName = fkColumnNames.Any()
? string.Join(",", fkPropertyNames)
: null;

association.SourceRole = navigationProperty.IsOnDependent ? AssociationRole.Dependent : AssociationRole.Principal;
association.TargetRole = navigationProperty.IsOnDependent ? AssociationRole.Principal : AssociationRole.Dependent;

//IProperty[] foreignKeyProperties = navigationProperty.JoinEntityType.GetForeignKeyProperties().ToArray();

//association.End1ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
// .Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType == entityType))
// .Select(x => x.GetColumnName(storeObjectIdentifier)));

//association.End2ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
// .Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType != entityType))
// .Select(x => x.GetColumnName(storeObjectIdentifier)));

// unfortunately, EFCore doesn't serialize documentation like EF6 did

//association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary;
Expand Down
30 changes: 24 additions & 6 deletions src/Utilities/EFCore7Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,36 @@ protected List<ModelUnidirectionalAssociation> GetUnidirectionalAssociations(IEn
// the property in the target class (referencing the source class)
association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.GetSourceMultiplicity());

List<string> fkPropertyDeclarations = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.Name)
.ToList();
List<string> fkPropertyNames = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.Name)
.ToList();

association.ForeignKey = fkPropertyDeclarations.Any()
? string.Join(",", fkPropertyDeclarations)
association.ForeignKey = fkPropertyNames.Any()
? string.Join(",", fkPropertyNames)
: null;

List<string> fkColumnNames = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.GetColumnName())
.ToList();
association.ForeignKeyColumnName = fkColumnNames.Any()
? string.Join(",", fkPropertyNames)
: null;

association.SourceRole = navigationProperty.IsOnDependent ? AssociationRole.Dependent : AssociationRole.Principal;
association.TargetRole = navigationProperty.IsOnDependent ? AssociationRole.Principal : AssociationRole.Dependent;

//IProperty[] foreignKeyProperties = navigationProperty.JoinEntityType.GetForeignKeyProperties().ToArray();

//association.End1ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
// .Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType == entityType))
// .Select(x => x.GetColumnName(storeObjectIdentifier)));

//association.End2ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
// .Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType != entityType))
// .Select(x => x.GetColumnName(storeObjectIdentifier)));

// unfortunately, EFCore doesn't serialize documentation like EF6 did

//association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary;
Expand Down
29 changes: 23 additions & 6 deletions src/Utilities/EFCore8Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,36 @@ protected List<ModelUnidirectionalAssociation> GetUnidirectionalAssociations(IEn
// the property in the target class (referencing the source class)
association.SourceMultiplicity = ConvertMultiplicity(navigationProperty.GetSourceMultiplicity());

List<string> fkPropertyDeclarations = navigationProperty.ForeignKey.Properties
List<string> fkPropertyNames = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.Name)
.ToList();
.Select(p => p.Name)
.ToList();

association.ForeignKey = fkPropertyDeclarations.Any()
? string.Join(",", fkPropertyDeclarations)
association.ForeignKey = fkPropertyNames.Any()
? string.Join(",", fkPropertyNames)
: null;

List<string> fkColumnNames = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.GetColumnName())
.ToList();
association.ForeignKeyColumnName = fkColumnNames.Any()
? string.Join(",", fkPropertyNames)
: null;

association.SourceRole = navigationProperty.IsOnDependent ? AssociationRole.Dependent : AssociationRole.Principal;
association.TargetRole = navigationProperty.IsOnDependent ? AssociationRole.Principal : AssociationRole.Dependent;

//IProperty[] foreignKeyProperties = navigationProperty.JoinEntityType.GetForeignKeyProperties().ToArray();

//association.End1ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
// .Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType == entityType))
// .Select(x => x.GetColumnName(storeObjectIdentifier)));

//association.End2ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
// .Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType != entityType))
// .Select(x => x.GetColumnName(storeObjectIdentifier)));

// unfortunately, EFCore doesn't serialize documentation like EF6 did

//association.TargetSummary = navigationProperty.ToEndMember.Documentation?.Summary;
Expand Down Expand Up @@ -356,7 +374,6 @@ private static void GetSkipBidirectionalAssociations(IEntityType entityType, Lis
association.End2ColumnName = string.Join(",", foreignKeyProperties.OfType<RuntimeProperty>()
.Where(p => p.ForeignKeys.Any(k => k.PrincipalEntityType != entityType))
.Select(x => x.GetColumnName(storeObjectIdentifier)));

result.Add(association);
}
}
Expand Down

0 comments on commit 2a31fda

Please sign in to comment.