Skip to content
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

Closes #545 Add option for additional using statements in the entity #546

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.AdditionalUsings = entity.AdditionalUsings;

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>
/// Additional using statements, ;-separated - example: MyLib;MyLib.Data;MyLib.Domain;MyLib.Domain.Interfaces
/// </summary>
public string AdditionalUsings { 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>
/// Additional using statements, ;-separated - example: MyLib;MyLib.Data;MyLib.Domain;MyLib.Domain.Interfaces
/// </summary>
public string AdditionalUsings { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public override string WriteCode()

CodeBuilder.AppendLine("using System;");
CodeBuilder.AppendLine("using System.Collections.Generic;");
if (!Options.Data.Entity.AdditionalUsings.IsNullOrWhiteSpace())
{
var splittedUsingEntries = Options.Data.Entity.AdditionalUsings.Split(';').Distinct()
.Where(s => !s.IsNullOrWhiteSpace());

foreach (var usingEntry in splittedUsingEntries)
CodeBuilder.AppendLine($"using {usingEntry};");
}
CodeBuilder.AppendLine();

CodeBuilder.Append($"namespace {_entity.EntityNamespace}");
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
additionalUsings: ''
renaming:
entities:
- ^(sp|tbl|udf|vw)_
Expand Down