Skip to content

Commit 28a0dc0

Browse files
Arnaud BoussaerArnaud Boussaer
Arnaud Boussaer
authored and
Arnaud Boussaer
committed
loresoft#547 Add option to add relationship property attributes
1 parent ceaa6a5 commit 28a0dc0

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/EntityFrameworkCore.Generator.Core/OptionMapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private static void MapEntity(EntityClassOptions option, EntityClass entity)
154154
option.EntityNaming = entity.EntityNaming;
155155
option.RelationshipNaming = entity.RelationshipNaming;
156156
option.PrefixWithSchemaName = entity.PrefixWithSchemaName;
157+
option.RelationshipAttributes = entity.RelationshipAttributes;
157158

158159
MapSelection(option.Renaming, entity.Renaming);
159160
}

src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public string BaseClass
7979
/// The renaming expressions.
8080
/// </value>
8181
public SelectionOptions Renaming { get; }
82+
83+
/// <summary>
84+
/// Attributes which are added to the generated relationships, ;-separated
85+
/// </summary>
86+
public string RelationshipAttributes { get; set; }
8287
}

src/EntityFrameworkCore.Generator.Core/Serialization/EntityClass.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ public EntityClass()
7070
/// The renaming expressions.
7171
/// </value>
7272
public SelectionModel Renaming { get; set; }
73+
74+
/// <summary>
75+
/// Attributes which are added to the generated relationships, ;-separated
76+
/// </summary>
77+
public string RelationshipAttributes { get; set; }
7378
}

src/EntityFrameworkCore.Generator.Core/Templates/EntityClassTemplate.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ private void GenerateRelationshipProperties()
177177
CodeBuilder.AppendLine("/// </value>");
178178
}
179179

180+
if (!Options.Data.Entity.RelationshipAttributes.IsNullOrWhiteSpace())
181+
{
182+
var splittedAttributes = Options.Data.Entity.RelationshipAttributes.Split(';').Distinct()
183+
.Where(s => !s.IsNullOrWhiteSpace());
184+
185+
foreach (var attribute in splittedAttributes)
186+
CodeBuilder.AppendLine($"[{attribute}]");
187+
}
180188

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

207+
if (!Options.Data.Entity.RelationshipAttributes.IsNullOrWhiteSpace())
208+
{
209+
var splittedAttributes = Options.Data.Entity.RelationshipAttributes.Split(';').Distinct()
210+
.Where(s => !s.IsNullOrWhiteSpace());
211+
212+
foreach (var attribute in splittedAttributes)
213+
CodeBuilder.AppendLine($"[{attribute}]");
214+
}
215+
199216
if (!Options.Project.Nullable)
200217
CodeBuilder.AppendLine($"public virtual {primaryFullName} {propertyName} {{ get; set; }}");
201218
else if (relationship.Cardinality == Cardinality.One)

test/EntityFrameworkCore.Generator.Core.Tests/Options/full.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ data:
3434
relationshipNaming: Plural
3535
document: false
3636
prefixWithSchemaName: false
37+
relationshipAttributes: ''
3738
renaming:
3839
entities:
3940
- ^(sp|tbl|udf|vw)_

0 commit comments

Comments
 (0)