Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
msawczyn committed Dec 15, 2020
1 parent d5f950a commit 4e352e1
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 114 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -59,6 +59,8 @@ to <a href="https://www.jetbrains.com/?from=EFDesigner"><img src="https://msawcz
- Fixes for code generation of new EFCore5 database collation options
- Fixed condition where sometimes generated code in entity default constructors would create infinitely recursive calls
- Stopped escaping standard XML comment tags in summary and description fields (see https://github.com/msawczyn/EFDesigner/issues/248)
- Asking for context factory method generation disables generation of OnCreating, since they don't play well together
- Due to the new seeding needs in EFCore5, setters for identity properties are now public even if set to be auto-generated

**3.0.1**
- Added [Description] attribute (to classes, properties, enums and enum values where summary was non-blank) to facilitate tooling use
Expand Down
2 changes: 2 additions & 0 deletions VSMarketplace blurb.md
Expand Up @@ -36,6 +36,8 @@ For comprehensive documentation, please visit [the project's documentation site]
- Fixes for code generation of new EFCore5 database collation options
- Fixed condition where sometimes generated code in entity default constructors would create infinitely recursive calls
- Stopped escaping standard XML comment tags in summary and description fields (see https://github.com/msawczyn/EFDesigner/issues/248)
- Asking for context factory method generation disables generation of OnCreating, since they don't play well together
- Due to the new seeding needs in EFCore5, setters for identity properties are now public even if set to be auto-generated

**3.0.1**
- **[NEW]** Added [Description] attribute (to classes, properties, enums and enum values where summary was non-blank) to facilitate tooling use
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Expand Up @@ -4,6 +4,8 @@
- Fixes for code generation of new EFCore5 database collation options
- Fixed condition where sometimes generated code in entity default constructors would create infinitely recursive calls
- Stopped escaping standard XML comment tags in summary and description fields (see https://github.com/msawczyn/EFDesigner/issues/248)
- Asking for context factory method generation disables generation of OnCreating, since they don't play well together
- Due to the new seeding needs in EFCore5, setters for identity properties are now public even if set to be auto-generated

3.0.1
- Added [Description] attribute (to classes, properties, enums and enum values where summary was non-blank) to facilitate tooling use
Expand Down
2 changes: 1 addition & 1 deletion src/Dsl/DslDefinition.dsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Dsl xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="9987f227-3d05-49b7-b151-857879f5dfb8" Description="Entity Framework visual editor for EF6, EFCore and beyond." Name="EFModel" DisplayName="Entity Framework Visual Editor" Namespace="Sawczyn.EFDesigner.EFModel" MajorVersion="3" Build="1" Revision="5" ProductName="EFDesigner" CompanyName="Michael Sawczyn" PackageGuid="56bbe1ba-aaee-4883-848f-e3c8656f8db2" PackageNamespace="Sawczyn.EFDesigner.EFModel" xmlns="http://schemas.microsoft.com/VisualStudio/2005/DslTools/DslDefinitionModel">
<Dsl xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="9987f227-3d05-49b7-b151-857879f5dfb8" Description="Entity Framework visual editor for EF6, EFCore and beyond." Name="EFModel" DisplayName="Entity Framework Visual Editor" Namespace="Sawczyn.EFDesigner.EFModel" MajorVersion="3" Build="2" ProductName="EFDesigner" CompanyName="Michael Sawczyn" PackageGuid="56bbe1ba-aaee-4883-848f-e3c8656f8db2" PackageNamespace="Sawczyn.EFDesigner.EFModel" xmlns="http://schemas.microsoft.com/VisualStudio/2005/DslTools/DslDefinitionModel">
<Classes>
<DomainClass Id="95532cb8-3452-4b09-a654-aeb2e2d0b3ad" Description="" Name="ModelRoot" DisplayName="Entity Model" Namespace="Sawczyn.EFDesigner.EFModel">
<CustomTypeDescriptor>
Expand Down
74 changes: 37 additions & 37 deletions src/Dsl/DslDefinition.dsl.diagram

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Dsl/GeneratedCode/DomainClasses.cs
Expand Up @@ -12822,6 +12822,6 @@ namespace Sawczyn.EFDesigner.EFModel
/// </summary>
partial class ModelRoot
{
public const string DSLVersion = "3.0.1.5";
public const string DSLVersion = "3.0.2.0";
}
}
4 changes: 2 additions & 2 deletions src/Dsl/GeneratedCode/SerializationHelper.cs
Expand Up @@ -1168,7 +1168,7 @@ public virtual void WriteRootElement(DslModeling::SerializationContext serializa
// Only model has schema, diagram has no schema.
rootElementSettings.SchemaTargetNamespace = "http://schemas.microsoft.com/dsltools/EFModel";
}
rootElementSettings.Version = new global::System.Version("3.0.1.5");
rootElementSettings.Version = new global::System.Version("3.0.2.0");

// Carry out the normal serialization.
rootSerializer.Write(serializationContext, rootElement, writer, rootElementSettings);
Expand All @@ -1190,7 +1190,7 @@ protected virtual void CheckVersion(DslModeling::SerializationContext serializat
throw new global::System.ArgumentNullException("reader");
#endregion

global::System.Version expectedVersion = new global::System.Version("3.0.1.5");
global::System.Version expectedVersion = new global::System.Version("3.0.2.0");
string dslVersionStr = reader.GetAttribute("dslVersion");
if (dslVersionStr != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DslPackage/GeneratedCode/Constants.cs
Expand Up @@ -18,7 +18,7 @@ internal static partial class Constants
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string CompanyName = @"Michael Sawczyn";
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string ProductVersion = "3.0.1.5";
public const string ProductVersion = "3.0.2.0";

// Menu definitions
public static readonly global::System.ComponentModel.Design.CommandID EFModelDiagramMenu = new global::System.ComponentModel.Design.CommandID(new global::System.Guid(EFModelCommandSetId), 0x10000);
Expand Down
3 changes: 2 additions & 1 deletion src/DslPackage/TextTemplates/EFCoreModelGenerator.ttinclude
Expand Up @@ -350,7 +350,8 @@
WriteDbSets();

WriteContextConstructors();
WriteOnConfiguring(segments);
if (!modelRoot.GenerateDbContextFactory)
WriteOnConfiguring(segments);
WriteOnModelCreate(segments, classesWithTables);

Output("}");
Expand Down
53 changes: 31 additions & 22 deletions src/DslPackage/TextTemplates/EFModelGenerator.ttinclude
Expand Up @@ -305,7 +305,7 @@
{
if (modelClass.DefaultConstructorVisibility == TypeAccessModifierExt.Default)
{
bool hasRequiredParameters = GetRequiredParameters(modelClass, false).Any();
bool hasRequiredParameters = GetRequiredParameters(modelClass, false, true).Any();

string visibility = (hasRequiredParameters || modelClass.IsAbstract) && !modelClass.IsDependentType
? "protected"
Expand Down Expand Up @@ -404,16 +404,21 @@
return requiredParameterNames;
}

protected List<string> GetRequiredParameters(ModelClass modelClass, bool? haveDefaults, bool? publicOnly = null)
/// <summary>Gets the local required properties for the ModelClass in formal parameter format</summary>
/// <param name="modelClass">Source</param>
/// <param name="haveDefaults">If true, only return those with default values. If false, only return those without default values. If null, return both.</param>
/// <param name="publicOnly">If true, only return those with public setters. If false, only return those without public setters. If null, return both.</param>
protected List<string> GetRequiredParameters(ModelClass modelClass, bool? haveDefaults, bool publicOnly = false)
{
List<string> requiredParameters = new List<string>();

if (haveDefaults != true)
{
// false or null - get those without default values
requiredParameters.AddRange(modelClass.AllRequiredAttributes
.Where(x => (!x.IsIdentity || x.IdentityType == IdentityType.Manual)
&& !x.IsConcurrencyToken
&& (x.SetterVisibility == SetterAccessModifier.Public || publicOnly != false)
&& (x.SetterVisibility == SetterAccessModifier.Public || !publicOnly)
&& string.IsNullOrEmpty(x.InitialValue))
.Select(x => $"{x.FQPrimitiveType} {x.Name.ToLower()}"));

Expand All @@ -426,10 +431,11 @@

if (haveDefaults != false)
{
// true or null - get those with default values
requiredParameters.AddRange(modelClass.AllRequiredAttributes
.Where(x => (!x.IsIdentity || x.IdentityType == IdentityType.Manual)
&& !x.IsConcurrencyToken
&& (x.SetterVisibility == SetterAccessModifier.Public || publicOnly != false)
&& (x.SetterVisibility == SetterAccessModifier.Public || !publicOnly)
&& !string.IsNullOrEmpty(x.InitialValue))
.Select(x =>
{
Expand Down Expand Up @@ -529,17 +535,11 @@
NL();
}

protected void WriteCommentBody(string comment)
protected string[] GenerateCommentBody(string comment)
{
List<string> result = new List<string>();
int chunkSize = 80;

string[] parts = comment.Split(new[]
{
"\r\n"
, "\r"
, "\n"
}
, StringSplitOptions.RemoveEmptyEntries);
string[] parts = comment.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

foreach (string value in parts)
{
Expand All @@ -560,9 +560,17 @@
else
text = string.Empty;

Output("/// " + SecurityElement.Escape(outputText));
result.Add(SecurityElement.Escape(outputText));
}
}

return result.ToArray();
}

protected void WriteCommentBody(string comment)
{
foreach (string s in GenerateCommentBody(comment))
Output($"/// {s}");
}

protected void WriteConstructor(ModelClass modelClass)
Expand All @@ -574,7 +582,7 @@
// Default constructor
/***********************************************************************/

bool hasRequiredParameters = GetRequiredParameters(modelClass, false).Any();
bool hasRequiredParameters = GetRequiredParameters(modelClass, false, true).Any();

bool hasOneToOneAssociations = modelClass.AllRequiredNavigationProperties()
.Any(np => np.AssociationObject.SourceMultiplicity == Sawczyn.EFDesigner.EFModel.Multiplicity.One
Expand Down Expand Up @@ -679,7 +687,7 @@
Output("/// </summary>");

WriteConstructorComments(modelClass);
Output($"{visibility} {modelClass.Name}({string.Join(", ", GetRequiredParameters(modelClass, null))})");
Output($"{visibility} {modelClass.Name}({string.Join(", ", GetRequiredParameters(modelClass, null, true))})");
Output("{");

if (remarks.Count > 0)
Expand Down Expand Up @@ -770,19 +778,20 @@
WriteConstructorComments(modelClass);

string newToken = string.Empty;
List<string> requiredParameters = GetRequiredParameters(modelClass, null);
List<string> requiredParameters = GetRequiredParameters(modelClass, null, true);

if (!AllSuperclassesAreNullOrAbstract(modelClass))
{
List<string> superclassRequiredParameters = GetRequiredParameters(modelClass.Superclass, null);
List<string> superclassRequiredParameters = GetRequiredParameters(modelClass.Superclass, null, true);

if (!requiredParameters.Except(superclassRequiredParameters).Any())
newToken = "new ";
}

Output($"public static {newToken}{modelClass.Name} Create({string.Join(", ", GetRequiredParameters(modelClass, null))})");
List<string> requiredParameterNames = requiredParameters.Select(p => p.Split(new[] {' '})[1]).ToList();
Output($"public static {newToken}{modelClass.Name} Create({string.Join(", ", requiredParameters)})");
Output("{");
Output($"return new {modelClass.Name}({string.Join(", ", GetRequiredParameterNames(modelClass))});");
Output($"return new {modelClass.Name}({string.Join(", ", requiredParameterNames)});");
Output("}");
NL();
}
Expand All @@ -794,7 +803,7 @@
foreach (ModelAttribute requiredAttribute in modelClass.AllRequiredAttributes.Where(x => (!x.IsIdentity || x.IdentityType == IdentityType.Manual)
&& !x.IsConcurrencyToken
&& x.SetterVisibility == SetterAccessModifier.Public))
Output($@"/// <param name=""{requiredAttribute.Name.ToLower()}"">{SecurityElement.Escape(requiredAttribute.Summary)}</param>");
Output($@"/// <param name=""{requiredAttribute.Name.ToLower()}"">{string.Join(" ", GenerateCommentBody(requiredAttribute.Summary))}</param>");

// TODO: Add comment if available
foreach (NavigationProperty requiredNavigationProperty in modelClass.AllRequiredNavigationProperties()
Expand Down Expand Up @@ -1179,7 +1188,7 @@
Output("/// </remarks>");
}

string setterVisibility = (modelAttribute.IsIdentity && modelAttribute.IdentityType != IdentityType.Manual) || modelAttribute.SetterVisibility == SetterAccessModifier.Protected
string setterVisibility = modelAttribute.SetterVisibility == SetterAccessModifier.Protected
? "protected "
: modelAttribute.SetterVisibility == SetterAccessModifier.Internal
? "internal "
Expand Down
Expand Up @@ -338,7 +338,8 @@ protected virtual void WriteDbContext()
WriteDbSets();

WriteContextConstructors();
WriteOnConfiguring(segments);
if (!modelRoot.GenerateDbContextFactory)
WriteOnConfiguring(segments);
WriteOnModelCreate(segments, classesWithTables);

Output("}");
Expand Down

0 comments on commit 4e352e1

Please sign in to comment.