Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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();
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data:
relationshipNaming: Plural
document: false
prefixWithSchemaName: false
relationshipAttributes: ''
renaming:
entities:
- ^(sp|tbl|udf|vw)_
Expand Down