Skip to content

Commit

Permalink
v2.4.3 initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
msawczyn committed Mar 30, 2023
1 parent c7e07d9 commit d921ea0
Show file tree
Hide file tree
Showing 60 changed files with 659 additions and 7,080 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ to <a href="https://www.jetbrains.com/?from=EFDesigner"><img src="https://msawcz

### Change Log

4.2.3 (next release - see [nightly builds](https://github.com/msawczyn/EFDesigner2022/blob/master/dist/Sawczyn.EFDesigner.EFModel.DslPackage.vsix) if interested)
[4.2.3](https://github.com/msawczyn/EFDesigner2022/releases/download/v4.2.3/Sawczyn.EFDesigner.EFModel.DslPackage.vsix)
- Added HierarchyId as a property type
- Added optional index name for indexed properties
- Added properties to bidirectional associations allowing custom naming of FK columns in join table
Expand All @@ -88,6 +88,7 @@ to <a href="https://www.jetbrains.com/?from=EFDesigner"><img src="https://msawcz
- Fix bad constructor generation when multiple associations exist between the same classes (see https://github.com/msawczyn/EFDesigner2022/issues/50)
- Removed modeling restriction on unidirectional many-to-many properties in EFCore7+ projects (see https://github.com/msawczyn/EFDesigner2022/issues/54)
- Updated file sync logic for generated files. Thanks to [Sancho-Lee](https://github.com/Sancho-Lee) for the pull request. (see https://github.com/msawczyn/EFDesigner2022/issues/57)
- Fix bad code re: key fields in derived types. (see https://github.com/msawczyn/EFDesigner2022/issues/55)

[4.2.1](https://github.com/msawczyn/EFDesigner2022/releases/download/v4.2.1/Sawczyn.EFDesigner.EFModel.DslPackage.vsix)
- Added support for EFCore7
Expand Down
1 change: 1 addition & 0 deletions VSMarketplace blurb.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ may be a bugfix or two your customized templates don't have. But, hey ... if you
- Fix bad constructor generation when multiple associations exist between the same classes (see https://github.com/msawczyn/EFDesigner2022/issues/50)
- Removed modeling restriction on unidirectional many-to-many properties in EFCore7+ projects (see https://github.com/msawczyn/EFDesigner2022/issues/54)
- Updated file sync logic for generated files. Thanks to [Sancho-Lee](https://github.com/Sancho-Lee) for the pull request. (see https://github.com/msawczyn/EFDesigner2022/issues/57)
- Fix bad code re: key fields in derived types. (see https://github.com/msawczyn/EFDesigner2022/issues/55)

**4.2.1**
- **[NEW]** Added support for EFCore7
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fix bad constructor generation when multiple associations exist between the same classes (see https://github.com/msawczyn/EFDesigner2022/issues/50)
- Removed modeling restriction on unidirectional many-to-many properties in EFCore7+ projects (see https://github.com/msawczyn/EFDesigner2022/issues/54)
- Updated file sync logic for generated files. Thanks to Sancho-Lee for the pull request. (see https://github.com/msawczyn/EFDesigner2022/issues/57)
- Fix bad code re: key fields in derived types. (see https://github.com/msawczyn/EFDesigner2022/issues/55)

4.2.1
- Added support for EFCore7
Expand Down
4 changes: 2 additions & 2 deletions dist/Sawczyn.EFDesigner.EFModel.DslPackage.vsix
Git LFS file not shown
4 changes: 2 additions & 2 deletions reload.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\VSIXInstaller.exe" /q /u:"56bbe1ba-aaee-4883-848f-e3c8656f8db2"
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\VSIXInstaller.exe" /q "dist\Sawczyn.EFDesigner.EFModel.DslPackage.vsix"
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VSIXInstaller.exe" /q /u:"56bbe1ba-aaee-4883-848f-e3c8656f8db2"
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VSIXInstaller.exe" /q "dist\Sawczyn.EFDesigner.EFModel.DslPackage.vsix"
39 changes: 21 additions & 18 deletions src/Dsl/CustomCode/Rules/ModelRootChangeRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)

if (element.EntityFrameworkVersion == EFVersion.EFCore)
{
if (element.IsEFCore5Plus)
{
if (element.InheritanceStrategy == CodeStrategy.TablePerConcreteType)
element.InheritanceStrategy = CodeStrategy.TablePerType;
}
else
{
// if we're not going to at least EFCore 5 we can only use the TablePerHierarchy strategy
if (!element.IsEFCore5Plus && element.InheritanceStrategy != CodeStrategy.TablePerHierarchy)
element.InheritanceStrategy = CodeStrategy.TablePerHierarchy;

// if we're not going to at least EFCore 7 we can't use the TablePerConcreteType strategy. Devolve to TablePerType.
else if (!element.IsEFCore7Plus && element.InheritanceStrategy == CodeStrategy.TablePerConcreteType)
element.InheritanceStrategy = CodeStrategy.TablePerType;

if (!element.IsEFCore5Plus)
store.ElementDirectory.AllElements.OfType<ModelClass>().Where(c => c.IsPropertyBag).ToList().ForEach(c => c.IsPropertyBag = false);
}
}


break;

case "EntityFrameworkVersion":
Expand All @@ -78,14 +79,16 @@ public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
{
case EFVersion.EFCore:
{
if (element.IsEFCore5Plus)
{
if (element.InheritanceStrategy == CodeStrategy.TablePerConcreteType)
element.InheritanceStrategy = CodeStrategy.TablePerType;
}
else
{
// if we're not going to at least EFCore 5 we can only use the TablePerHierarchy strategy
if (!element.IsEFCore5Plus && element.InheritanceStrategy != CodeStrategy.TablePerHierarchy)
element.InheritanceStrategy = CodeStrategy.TablePerHierarchy;

// if we're not going to at least EFCore 7 we can't use the TablePerConcreteType strategy. Devolve to TablePerType.
else if (!element.IsEFCore7Plus && element.InheritanceStrategy == CodeStrategy.TablePerConcreteType)
element.InheritanceStrategy = CodeStrategy.TablePerType;

if (!element.IsEFCore5Plus)
{
store.ElementDirectory.AllElements.OfType<ModelClass>().Where(c => c.IsPropertyBag).ToList().ForEach(c => c.IsPropertyBag = false);

switch (element.PropertyAccessModeDefault)
Expand Down Expand Up @@ -194,11 +197,11 @@ public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)

if (element.EntityFrameworkVersion == EFVersion.EFCore)
{
if (element.IsEFCore5Plus && (element.InheritanceStrategy == CodeStrategy.TablePerConcreteType))
element.InheritanceStrategy = CodeStrategy.TablePerType;

if (!element.IsEFCore5Plus)
element.InheritanceStrategy = CodeStrategy.TablePerHierarchy;

if (!element.IsEFCore7Plus && element.InheritanceStrategy == CodeStrategy.TablePerConcreteType)
element.InheritanceStrategy = CodeStrategy.TablePerType;
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
ModelRoot modelRoot = store.ModelRoot();

// Value set changes at EFCore5
if (modelRoot.EntityFrameworkVersion == EFVersion.EF6)
if (modelRoot.IsEFCore6Plus)
{
values.AddRange(new[] {"TablePerConcreteType", "TablePerHierarchy", "TablePerType"});
}
Expand Down
1 change: 1 addition & 0 deletions src/Dsl/Dsl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Sawczyn.EFDesigner.EFModel.Dsl.xml</DocumentationFile>
<NoWarn>CS3001,VSTHRD010,CS3009;MSB3277</NoWarn>
</PropertyGroup>
<!-- Project specific properties to control T4/DSL targets -->
<PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Dsl/GeneratedCode/DomainClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ public override sealed void SetValue(ModelRoot element, CodeStrategy newValue)
/// <summary>
/// Gets or sets the value of DefaultCollectionClass domain property.
/// The type of container generated to represent associations if not overridden.
/// Must implement ICollection<T>.
/// Must implement ICollection[[T]].
/// </summary>
[System.ComponentModel.TypeConverter(typeof(CollectionTypeTypeConverter))]
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.ModelRoot/DefaultCollectionClass.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down Expand Up @@ -6936,7 +6936,7 @@ public override sealed void SetValue(ModelClass element, global::System.Boolean

/// <summary>
/// Gets or sets the value of IsPropertyBag domain property.
/// If true, this class will be implemented as Dictionary<string, object>
/// If true, this class will be implemented as Dictionary[[string, object]]
/// </summary>
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.ModelClass/IsPropertyBag.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::CategoryResource("Sawczyn.EFDesigner.EFModel.ModelClass/IsPropertyBag.Category", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down Expand Up @@ -10798,7 +10798,7 @@ public override sealed void SetValue(ModelAttribute element, global::System.Stri

/// <summary>
/// Gets or sets the value of DisplayText domain property.
/// Text for [Display(Name="<text>")] attribute
/// Text for [Display(Name="text")] attribute
/// </summary>
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.ModelAttribute/DisplayText.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::CategoryResource("Sawczyn.EFDesigner.EFModel.ModelAttribute/DisplayText.Category", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down Expand Up @@ -14183,7 +14183,7 @@ public override sealed void SetValue(ModelEnumValue element, global::System.Stri

/// <summary>
/// Gets or sets the value of DisplayText domain property.
/// Text for [Display(Name="<text>")] attribute
/// Text for [Display(Name="text")] attribute
/// </summary>
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.ModelEnumValue/DisplayText.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::CategoryResource("Sawczyn.EFDesigner.EFModel.ModelEnumValue/DisplayText.Category", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down
6 changes: 3 additions & 3 deletions src/Dsl/GeneratedCode/DomainRelationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ public override sealed void SetValue(Association element, DeleteAction newValue)

/// <summary>
/// Gets or sets the value of CollectionClass domain property.
/// Class used to instanciate association properties. Implements ICollection<>
/// Class used to instanciate association properties. Implements ICollection[[]]
/// </summary>
[System.ComponentModel.TypeConverter(typeof(CollectionTypeTypeConverter))]
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.Association/CollectionClass.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down Expand Up @@ -1599,7 +1599,7 @@ public override sealed void SetValue(Association element, global::System.String

/// <summary>
/// Gets or sets the value of TargetDisplayText domain property.
/// Text for [Display(Name="<text>")] attribute on this end's property
/// Text for [Display(Name="text")] attribute on this end's property
/// </summary>
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.Association/TargetDisplayText.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::CategoryResource("Sawczyn.EFDesigner.EFModel.Association/TargetDisplayText.Category", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down Expand Up @@ -4334,7 +4334,7 @@ public override sealed void SetValue(BidirectionalAssociation element, global::S

/// <summary>
/// Gets or sets the value of SourceDisplayText domain property.
/// Text for [Display(Name="<text>")] attribute on this end's property
/// Text for [Display(Name="text")] attribute on this end's property
/// </summary>
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.BidirectionalAssociation/SourceDisplayText.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::CategoryResource("Sawczyn.EFDesigner.EFModel.BidirectionalAssociation/SourceDisplayText.Category", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Expand Down
2 changes: 1 addition & 1 deletion src/Dsl/MefExtension/DesignerExtensionMetaDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public object EFModelExtensionFilter
/// Provides a strongly typed custom attribute which allows user to use the following:
/// [EFModelValidationExtension]
/// in lieu of
/// [Export(typeof(typeof(Action<ValidationContext, object>))]
/// [Export(typeof(typeof(Action[[ValidationContext, object]]))]
/// [ExportMetadata("EFModelExtensionFilter", null)]
///
/// Use this attribute to Export a ValidationExtension MEF part for EFModel designer.
Expand Down
15 changes: 2 additions & 13 deletions src/DslPackage/DslPackage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>CS1762,VSTHRD010,VSTHRD001;MSB3277</NoWarn>
<DocumentationFile>bin\Release\Sawczyn.EFDesigner.EFModel.DslPackage.xml</DocumentationFile>
</PropertyGroup>
<!-- Properties for VSSDK/DSL Targets: Must be defined before importing the targets -->
<PropertyGroup>
Expand Down Expand Up @@ -286,18 +288,6 @@
<Content Include="TextTemplates\EFModelGenerator.ttinclude">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Compile Include="TextTemplates\EditingOnly\EF6Designer.cs" />
<Compile Include="TextTemplates\EditingOnly\EF6ModelGenerator.cs" />
<Compile Include="TextTemplates\EditingOnly\EFCore2ModelGenerator.cs" />
<Compile Include="TextTemplates\EditingOnly\EFCore3ModelGenerator.cs" />
<Compile Include="TextTemplates\EditingOnly\EFCore5ModelGenerator.cs" />
<Compile Include="TextTemplates\EditingOnly\EFCoreDesigner.cs" />
<Compile Include="TextTemplates\EditingOnly\EFCoreModelGenerator.cs" />
<Compile Include="TextTemplates\EditingOnly\EFDesigner.cs" />
<Compile Include="TextTemplates\EditingOnly\EFModelFileManager.cs" />
<Compile Include="TextTemplates\EditingOnly\EFModelGenerator.cs" />
<Compile Include="TextTemplates\EditingOnly\MultipleOutputHelper.cs" />
<Compile Include="TextTemplates\EditingOnly\VSIntegration.cs" />
<Compile Include="VSPackage.Designer.cs" />
<Content Include="Logo.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -396,7 +386,6 @@
<Content Include="TextTemplates\VSIntegration.ttinclude">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="TextTemplates\EditingOnly\_ReadMe.md" />
<None Include="TextTemplates\EF6Designer.ttinclude" />
<None Include="TextTemplates\EFCoreDesigner.ttinclude" />
</ItemGroup>
Expand Down
23 changes: 13 additions & 10 deletions src/DslPackage/TextTemplates/EFCore5ModelGenerator.ttinclude
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,21 @@
: $"ToTable(\"{tableName}\"{schema}{buildActions})");

if (modelClass.Superclass != null)
{
segments.Add($"HasBaseType<{modelClass.Superclass.FullName}>()");
}
else // if there's a base class, we can't have new identifiers
{
// primary key code segments must be output last, since HasKey returns a different type
List<ModelAttribute> allIdentityAttributes = modelClass.AllIdentityAttributes.ToList();

// primary key code segments must be output last, since HasKey returns a different type
List<ModelAttribute> identityAttributes = modelClass.IdentityAttributes.ToList();

if (identityAttributes.Count == 1)
segments.Add($"HasKey(t => t.{identityAttributes[0].Name})");
else if (identityAttributes.Count > 1)
segments.Add($"HasKey(t => new {{ t.{string.Join(", t.", identityAttributes.Select(ia => ia.Name))} }})");
else
segments.Add("HasNoKey()");
}
if (allIdentityAttributes.Count == 1)
segments.Add($"HasKey(t => t.{allIdentityAttributes[0].Name})");
else if (allIdentityAttributes.Count > 1)
segments.Add($"HasKey(t => new {{ t.{string.Join(", t.", allIdentityAttributes.Select(ia => ia.Name))} }})");
else
segments.Add("HasNoKey()");
} }

[SuppressMessage("ReSharper", "RedundantNameQualifier")]
protected override void ConfigureUnidirectionalAssociations(ModelClass modelClass, List<Association> visited, List<string> foreignKeyColumns, List<string> declaredShadowProperties)
Expand Down
20 changes: 19 additions & 1 deletion src/DslPackage/TextTemplates/EFModelFileManager.ttinclude
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,26 @@
ProjectSync(generatedFileNames);
}

private bool ShouldDelete(string[] targetFileNames, string fileName)
{
Dictionary<string, string> directories = new Dictionary<string, string>();

foreach (string targetFilename in targetFileNames)
{
string directory = Path.GetDirectoryName(targetFilename);
if (directory != null)
{
if (!directories.ContainsKey(directory))
directories.Add(directory, targetFilename);
}
}
return directories.ContainsKey(Path.GetDirectoryName(fileName));
}

private void ProjectSync(IEnumerable<string> keepFileNames)
{
// thanks to Sancho-Lee (https://github.com/Sancho-Lee) for the fix here

Dictionary<ProjectItem, List<string>> current = GetCurrentState();

string[] fileNames = keepFileNames as string[] ?? keepFileNames.ToArray();
Expand All @@ -356,7 +374,7 @@
{
foreach (string filename in current[parentItem])
{
if (!allTargetFiles.Contains(filename) && !fileNames.Contains(filename))
if (!allTargetFiles.Contains(filename) && ShouldDelete(fileNames, filename))
dte.Solution.FindProjectItem(filename)?.Delete();
else
existingFiles.Add(filename);
Expand Down
Loading

0 comments on commit d921ea0

Please sign in to comment.