-
Notifications
You must be signed in to change notification settings - Fork 54
Update to emit transformed NavPropertyNames #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bc0909a
Merge pull request #1 from TrackableEntities/master
dmayhak 56ef73e
Updates to transform NavPropertyNames
dmayhak 3176590
merge
dmayhak 9600d08
Clean up csproj file
dmayhak 99ceed5
Merge branch 'master' of https://github.com/dmayhak/EntityFrameworkCo…
dmayhak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ public class HbsCSharpDbContextGenerator : CSharpDbContextGenerator | |
| /// <param name="entityTypeTransformationService">Service for transforming entity definitions.</param> | ||
| /// <param name="options">Handlebars scaffolding options.</param> | ||
| public HbsCSharpDbContextGenerator( | ||
| [NotNull] IProviderConfigurationCodeGenerator providerConfigurationCodeGenerator, | ||
| [NotNull] IProviderConfigurationCodeGenerator providerConfigurationCodeGenerator, | ||
| [NotNull] IAnnotationCodeGenerator annotationCodeGenerator, | ||
| [NotNull] IDbContextTemplateService dbContextTemplateService, | ||
| [NotNull] IEntityTypeTransformationService entityTypeTransformationService, | ||
|
|
@@ -137,7 +137,7 @@ public override string WriteCode(IModel model, string contextName, string connec | |
| /// <param name="useDataAnnotations">Use fluent modeling API if false.</param> | ||
| /// <param name="suppressConnectionStringWarning">Suppress connection string warning.</param> | ||
| protected override void GenerateClass( | ||
| IModel model, string contextName, string connectionString, bool useDataAnnotations, | ||
| IModel model, string contextName, string connectionString, bool useDataAnnotations, | ||
| bool suppressConnectionStringWarning) | ||
| { | ||
| Check.NotNull(model, nameof(model)); | ||
|
|
@@ -206,7 +206,7 @@ protected override void GenerateOnConfiguring(string connectionString, bool supp | |
| sb.AppendLine("}"); | ||
| } | ||
|
|
||
| sb.AppendLine("}"); | ||
| sb.AppendLine("}"); | ||
| } | ||
|
|
||
| var onConfiguring = sb.ToString(); | ||
|
|
@@ -501,7 +501,7 @@ private void GenerateKey(IKey key, IEntityType entityType, bool useDataAnnotatio | |
|
|
||
| var lines = new List<string> | ||
| { | ||
| $".{nameof(EntityTypeBuilder.HasKey)}(e => {GenerateLambdaToKey(key.Properties, "e")})" | ||
| $".{nameof(EntityTypeBuilder.HasKey)}(e => {GenerateLambdaToKey(key.Properties, "e", EntityTypeTransformationService.TransformPropertyName)})" | ||
| }; | ||
|
|
||
| if (explicitName) | ||
|
|
@@ -567,7 +567,7 @@ private void GenerateIndex(IIndex index, IndentedStringBuilder sb) | |
| { | ||
| var lines = new List<string> | ||
| { | ||
| $".{nameof(EntityTypeBuilder.HasIndex)}(e => {GenerateLambdaToKey(index.Properties, "e")})" | ||
| $".{nameof(EntityTypeBuilder.HasIndex)}(e => {GenerateLambdaToKey(index.Properties, "e", EntityTypeTransformationService.TransformPropertyName)})" | ||
| }; | ||
|
|
||
| var annotations = index.GetAnnotations().ToList(); | ||
|
|
@@ -622,7 +622,7 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations, Inden | |
| { | ||
| var lines = new List<string> | ||
| { | ||
| $".{nameof(EntityTypeBuilder.Property)}(e => e.{property.Name})" | ||
| $".{nameof(EntityTypeBuilder.Property)}(e => e.{EntityTypeTransformationService.TransformPropertyName(property.Name)})" | ||
| }; | ||
|
|
||
| var annotations = property.GetAnnotations().ToList(); | ||
|
|
@@ -799,9 +799,9 @@ private void GenerateRelationship(IForeignKey foreignKey, bool useDataAnnotation | |
|
|
||
| var lines = new List<string> | ||
| { | ||
| $".{nameof(EntityTypeBuilder.HasOne)}(" + (foreignKey.DependentToPrincipal != null ? $"d => d.{foreignKey.DependentToPrincipal.Name}" : null) + ")", | ||
| $".{nameof(EntityTypeBuilder.HasOne)}(" + (foreignKey.DependentToPrincipal != null ? $"d => d.{EntityTypeTransformationService.TransformNavPropertyName(foreignKey.DependentToPrincipal.Name)}" : null) + ")", | ||
| $".{(foreignKey.IsUnique ? nameof(ReferenceNavigationBuilder.WithOne) : nameof(ReferenceNavigationBuilder.WithMany))}" | ||
| + $"(" + (foreignKey.PrincipalToDependent != null ? $"p => p.{foreignKey.PrincipalToDependent.Name}" : null) + ")" | ||
| + $"(" + (foreignKey.PrincipalToDependent != null ? $"p => p.{EntityTypeTransformationService.TransformNavPropertyName(foreignKey.PrincipalToDependent.Name)}" : null) + ")" | ||
| }; | ||
|
|
||
| if (!foreignKey.PrincipalKey.IsPrimaryKey()) | ||
|
|
@@ -810,13 +810,13 @@ private void GenerateRelationship(IForeignKey foreignKey, bool useDataAnnotation | |
| lines.Add( | ||
| $".{nameof(ReferenceReferenceBuilder.HasPrincipalKey)}" | ||
| + (foreignKey.IsUnique ? $"<{((ITypeBase)foreignKey.PrincipalEntityType).DisplayName()}>" : "") | ||
| + $"(p => {GenerateLambdaToKey(foreignKey.PrincipalKey.Properties, "p")})"); | ||
| + $"(p => {GenerateLambdaToKey(foreignKey.PrincipalKey.Properties, "p", EntityTypeTransformationService.TransformNavPropertyName)})"); | ||
| } | ||
|
|
||
| lines.Add( | ||
| $".{nameof(ReferenceReferenceBuilder.HasForeignKey)}" | ||
| + (foreignKey.IsUnique ? $"<{((ITypeBase)foreignKey.DeclaringEntityType).DisplayName()}>" : "") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 818 should be: + (foreignKey.IsUnique ? $"<{EntityTypeTransformationService.TransformPropertyName(((ITypeBase)foreignKey.DeclaringEntityType).DisplayName())}>" : "")
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmayhak You still need to make this change, so that generic type arguments are transformed. |
||
| + $"(d => {GenerateLambdaToKey(foreignKey.Properties, "d")})"); | ||
| + $"(d => {GenerateLambdaToKey(foreignKey.Properties, "d", EntityTypeTransformationService.TransformPropertyName)})"); | ||
|
|
||
| var defaultOnDeleteAction = foreignKey.IsRequired | ||
| ? DeleteBehavior.Cascade | ||
|
|
@@ -939,15 +939,16 @@ private void GenerateSequence(ISequence sequence, IndentedStringBuilder sb) | |
| sb.AppendLine(";"); | ||
| } | ||
|
|
||
| private static string GenerateLambdaToKey( | ||
| private string GenerateLambdaToKey( | ||
| IReadOnlyList<IProperty> properties, | ||
| string lambdaIdentifier) | ||
| string lambdaIdentifier, | ||
| Func<string, string> nameTransform ) | ||
| { | ||
| return properties.Count <= 0 | ||
| ? "" | ||
| : properties.Count == 1 | ||
| ? $"{lambdaIdentifier}.{properties[0].Name}" | ||
| : $"new {{ {string.Join(", ", properties.Select(p => lambdaIdentifier + "." + p.Name))} }}"; | ||
| ? $"{lambdaIdentifier}.{nameTransform(properties[0].Name)}" | ||
| : $"new {{ {string.Join(", ", properties.Select(p => lambdaIdentifier + "." + nameTransform(p.Name)))} }}"; | ||
| } | ||
|
|
||
| private static void RemoveAnnotation(ref List<IAnnotation> annotations, string annotationName) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 812 should be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmayhak You still need to make this change, so that generic type arguments are transformed.