Skip to content

Closes #547 Add option to add relationship property attributes #548

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/EntityFrameworkCore.Generator.Core/OptionMapper.cs
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@ private static void MapEntity(EntityClassOptions option, EntityClass entity)
option.EntityNaming = entity.EntityNaming;
option.RelationshipNaming = entity.RelationshipNaming;
option.PrefixWithSchemaName = entity.PrefixWithSchemaName;
option.RelationshipAttributes = entity.RelationshipAttributes;

MapSelection(option.Renaming, entity.Renaming);
}
Original file line number Diff line number Diff line change
@@ -79,4 +79,9 @@ public string BaseClass
/// The renaming expressions.
/// </value>
public SelectionOptions Renaming { get; }

/// <summary>
/// Attributes which are added to the generated relationships, ;-separated
/// </summary>
public string RelationshipAttributes { get; set; }
}
Original file line number Diff line number Diff line change
@@ -70,4 +70,9 @@ public EntityClass()
/// The renaming expressions.
/// </value>
public SelectionModel Renaming { get; set; }

/// <summary>
/// Attributes which are added to the generated relationships, ;-separated
/// </summary>
public string RelationshipAttributes { get; set; }
}
Original file line number Diff line number Diff line change
@@ -177,6 +177,14 @@ private void GenerateRelationshipProperties()
CodeBuilder.AppendLine("/// </value>");
}

if (!Options.Data.Entity.RelationshipAttributes.IsNullOrWhiteSpace())
{
var splittedAttributes = Options.Data.Entity.RelationshipAttributes.Split(';').Distinct()
.Where(s => !s.IsNullOrWhiteSpace());

foreach (var attribute in splittedAttributes)
CodeBuilder.AppendLine($"[{attribute}]");
}

CodeBuilder.AppendLine($"public virtual ICollection<{primaryFullName}> {propertyName} {{ get; set; }}");
CodeBuilder.AppendLine();
@@ -196,6 +204,15 @@ private void GenerateRelationshipProperties()
CodeBuilder.AppendLine($"/// <seealso cref=\"{property.PropertyName}\" />");
}

if (!Options.Data.Entity.RelationshipAttributes.IsNullOrWhiteSpace())
{
var splittedAttributes = Options.Data.Entity.RelationshipAttributes.Split(';').Distinct()
.Where(s => !s.IsNullOrWhiteSpace());

foreach (var attribute in splittedAttributes)
CodeBuilder.AppendLine($"[{attribute}]");
}

if (!Options.Project.Nullable)
CodeBuilder.AppendLine($"public virtual {primaryFullName} {propertyName} {{ get; set; }}");
else if (relationship.Cardinality == Cardinality.One)
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ data:
relationshipNaming: Plural
document: false
prefixWithSchemaName: false
relationshipAttributes: ''
renaming:
entities:
- ^(sp|tbl|udf|vw)_