Skip to content

Commit

Permalink
Merge pull request #239 from mwmccallum/fix/Bug238MultipleSchema
Browse files Browse the repository at this point in the history
Fixed issue for Multiple Schema FK. Added back removed code that generated additional annotations.
  • Loading branch information
tonysneed committed Dec 30, 2023
2 parents 144cb9e + a94a562 commit a449f1e
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ private void GenerateEntityType(IEntityType entityType, IndentedStringBuilder sb
{
GenerateKey(entityType.FindPrimaryKey(), entityType, sb);

// Add HasTriggers Fluent method added for EF7+
entityType.GetDeclaredTriggers()
.ToList()
.ForEach(t => GenerateTrigger(entityType, t, sb));

var annotations = AnnotationCodeGenerator
.FilterIgnoredAnnotations(entityType.GetAnnotations())
.ToDictionary(a => a.Name, a => a);
Expand Down Expand Up @@ -511,6 +516,20 @@ private void GenerateKey(IKey key, IEntityType entityType, IndentedStringBuilder
AppendMultiLineFluentApi(key.DeclaringEntityType, lines, sb);
}

/// <summary>
/// Generate Trigger Fluent API
/// </summary>
/// <param name="entityType"></param>
/// <param name="trigger"></param>
/// <param name="sb"></param>
private void GenerateTrigger(IEntityType entityType, ITrigger trigger, IndentedStringBuilder sb)
{
var parameterString = $"e => e.HasTrigger ( \"{trigger.ModelName}\" ) ";
var lines = new List<string> { $".{nameof(RelationalEntityTypeBuilderExtensions.ToTable)}({parameterString})" };

AppendMultiLineFluentApi(entityType, lines, sb);
}

private void GenerateTableName(IEntityType entityType, IndentedStringBuilder sb)
{
var tableName = entityType.GetTableName();
Expand Down Expand Up @@ -660,12 +679,14 @@ private void GenerateProperty(IEntityType entityType, IProperty property, bool u
{
lines.Add($".{nameof(RelationalPropertyBuilderExtensions.HasDefaultValue)}()");
annotations.Remove(RelationalAnnotationNames.DefaultValue);
annotations.Remove(RelationalAnnotationNames.DefaultValueSql);
}
else if (defaultValue != null)
{
lines.Add(
$".{nameof(RelationalPropertyBuilderExtensions.HasDefaultValue)}({CSharpHelper.UnknownLiteral(defaultValue)})");
annotations.Remove(RelationalAnnotationNames.DefaultValue);
annotations.Remove(RelationalAnnotationNames.DefaultValueSql);
}
}

Expand Down Expand Up @@ -696,6 +717,10 @@ private void GenerateProperty(IEntityType entityType, IProperty property, bool u
lines.Add($".{nameof(PropertyBuilder.IsConcurrencyToken)}()");
}

lines.AddRange(
AnnotationCodeGenerator.GenerateFluentApiCalls(property, annotations).Select(m => CSharpHelper.Fragment(m))
.Concat(GenerateAnnotations(annotations.Values)));

switch (lines.Count)
{
case 1:
Expand Down Expand Up @@ -738,7 +763,7 @@ private void GenerateRelationship(IEntityType entityType, IForeignKey foreignKey

lines.Add(
$".{nameof(ReferenceReferenceBuilder.HasForeignKey)}"
+ (foreignKey.IsUnique ? $"<{GetEntityTypeName(foreignKey.PrincipalEntityType, EntityTypeTransformationService.TransformTypeEntityName(foreignKey.DeclaringEntityType.Name))}>" : "")
+ (foreignKey.IsUnique ? $"<{GetEntityTypeName(entityType, EntityTypeTransformationService.TransformTypeEntityName(entityType.Name))}>" : "")
+ $"(d => {GenerateLambdaToKey(entityType, foreignKey.Properties, "d", EntityTypeTransformationService.TransformPropertyName)})");

var defaultOnDeleteAction = foreignKey.IsRequired
Expand Down

0 comments on commit a449f1e

Please sign in to comment.