Skip to content

Commit 0f6cdda

Browse files
committed
Added support for singular DBSet names
1 parent b5a179e commit 0f6cdda

File tree

16 files changed

+186
-20
lines changed

16 files changed

+186
-20
lines changed

Modules/Intent.Modules.Application.DomainInteractions/DataAccessProviders/DbContextDataAccessProvider.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
31
using Intent.Exceptions;
42
using Intent.Metadata.Models;
53
using Intent.Modelers.Domain.Api;
4+
using Intent.Modules.Common;
65
using Intent.Modules.Common.CSharp.Builder;
76
using Intent.Modules.Common.CSharp.Interactions;
87
using Intent.Modules.Common.CSharp.Mapping;
98
using Intent.Modules.Common.CSharp.Templates;
109
using Intent.Modules.Common.Templates;
1110
using Intent.Modules.Constants;
11+
using System.Collections.Generic;
12+
using System.Linq;
13+
using System.Threading;
14+
using static Intent.Modules.Constants.TemplateRoles.Domain;
1215

1316
namespace Intent.Modules.Application.DomainInteractions.DataAccessProviders;
1417

@@ -32,7 +35,9 @@ public DbContextDataAccessProvider(
3235
_dbContextField = dbContextField;
3336
_template = template;
3437
_mappingManager = mappingManager;
35-
_dbSetAccessor = new CSharpAccessMemberStatement(_dbContextField, entity.Name.ToPascalCase().Pluralize());
38+
39+
_dbSetAccessor = new CSharpAccessMemberStatement(_dbContextField, GetDbSetName(entity));
40+
3641
var entityTemplate = _template.GetTemplate<ICSharpFileBuilderTemplate>(TemplateRoles.Domain.Entity.Primary, entity);
3742
_pks = entityTemplate.CSharpFile.Classes.First().GetPropertiesWithPrimaryKey();
3843
_isUsingProjections = queryContext?.ImplementWithProjections() == true;
@@ -294,4 +299,14 @@ public CSharpStatement FindAllAsync(IElementToElementMapping queryMapping, strin
294299
prerequisiteStatements = new List<CSharpStatement>();
295300
return new CSharpStatement("");
296301
}
302+
303+
public string GetDbSetName(ClassModel model)
304+
{
305+
if (_template.ExecutionContext.Settings.GetSetting("ac0a788e-d8b3-4eea-b56d-538608f1ded9", "6010e890-6e2d-4812-9969-ffbdb8f93d87")?.Value == "same-as-entity")
306+
{
307+
return model.Name.ToPascalCase();
308+
}
309+
310+
return model.Name.ToPascalCase().Pluralize();
311+
}
297312
}

Modules/Intent.Modules.Application.DomainInteractions/Intent.Application.DomainInteractions.imodspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.Application.DomainInteractions</id>
4-
<version>1.1.7-pre.1</version>
4+
<version>1.1.7-pre.2</version>
55
<supportedClientVersions>[4.5.15-a,5.0.0)</supportedClientVersions>
66
<summary>Provides interaction strategies to generate domain interaction implementations.</summary>
77
<description>Provides interaction strategies to generate domain interaction implementations.</description>

Modules/Intent.Modules.Application.DomainInteractions/Intent.Modules.Application.DomainInteractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.7-pre.1</Version>
5+
<Version>1.1.7-pre.2</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

Modules/Intent.Modules.Application.DomainInteractions/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Improvement: Checking for installed mappers are more flexible.
44
- Fixed: CRUD not explicitly calls SaveChanges for EF when modeling Auto-generated primary keys.
5+
- Improvement: Added support for singular DBSet names
56

67
### Version 1.1.6
78

Modules/Intent.Modules.AspNetCore.OData.EntityFramework/Intent.AspNetCore.OData.EntityFramework.imodspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.AspNetCore.OData.EntityFramework</id>
4-
<version>1.0.6</version>
4+
<version>1.0.7-pre.0</version>
55
<supportedClientVersions>[4.3.0-a,5.0.0)</supportedClientVersions>
66
<summary>Provide the ability to expose OData endpoints for a Domain Model.</summary>
77
<description>Enable the application to expose OData endpoints that operate directly over the Domain Model, allowing clients to query, filter, and manipulate domain entities using standard OData protocols.</description>

Modules/Intent.Modules.AspNetCore.OData.EntityFramework/Templates/ODataAggregateController/ODataAggregateControllerTemplatePartial.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Intent.Modules.Common;
88
using Intent.Modules.Common.CSharp.Builder;
99
using Intent.Modules.Common.CSharp.Templates;
10+
using Intent.Modules.Common.FileBuilders;
1011
using Intent.Modules.Common.Templates;
1112
using Intent.Modules.Constants;
1213
using Intent.Modules.EntityFrameworkCore.Templates;
@@ -55,13 +56,14 @@ public ODataAggregateControllerTemplate(IOutputTarget outputTarget, ClassModel m
5556
return;
5657
}
5758

59+
var dbSetName = GetDbSetName(model);
60+
5861
if (stereotype.GetAll())
5962
{
6063
@class.AddMethod($"IQueryable<{GetTypeName(Model.InternalElement)}>", "Get", method =>
6164
{
6265
method.AddAttribute(new CSharpAttribute("[HttpGet]"));
63-
64-
method.AddStatement($"return _context.{Model.Name.Pluralize().ToPascalCase()};");
66+
method.AddStatement($"return _context.{dbSetName};");
6567
});
6668
}
6769

@@ -73,7 +75,7 @@ public ODataAggregateControllerTemplate(IOutputTarget outputTarget, ClassModel m
7375
method.AddAttribute(new CSharpAttribute("[HttpGet]"));
7476

7577
var linqQuery = GeneratePrimaryKeyParameters(model, method, c => c.AddAttribute("[FromODataUri]"));
76-
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{Model.Name.Pluralize().ToPascalCase()}.FirstOrDefaultAsync({linqQuery});");
78+
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{dbSetName}.FirstOrDefaultAsync({linqQuery});");
7779
method.AddStatement($"return {Model.Name.ToCamelCase()} == null ? NotFound() : Ok({Model.Name.ToCamelCase()});", s => s.SeparatedFromPrevious());
7880
});
7981
}
@@ -86,7 +88,7 @@ public ODataAggregateControllerTemplate(IOutputTarget outputTarget, ClassModel m
8688
method.AddAttribute(new CSharpAttribute("[HttpPost]"));
8789

8890
method.AddParameter($"{GetTypeName(Model.InternalElement)}", $"{Model.Name.ToCamelCase()}", p => p.AddAttribute("[FromBody]"));
89-
method.AddStatement($"await _context.{Model.Name.Pluralize().ToPascalCase()}.AddAsync({Model.Name.ToCamelCase()});");
91+
method.AddStatement($"await _context.{dbSetName}.AddAsync({Model.Name.ToCamelCase()});");
9092
method.AddStatement($"await _context.SaveChangesAsync();");
9193
method.AddStatement($"return Created({Model.Name.ToCamelCase()});", s => s.SeparatedFromPrevious());
9294
});
@@ -101,10 +103,10 @@ public ODataAggregateControllerTemplate(IOutputTarget outputTarget, ClassModel m
101103

102104
var linqQuery = GeneratePrimaryKeyParameters(model, method, c => c.AddAttribute("[FromODataUri]"));
103105

104-
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{Model.Name.Pluralize().ToPascalCase()}.SingleOrDefaultAsync({linqQuery});");
106+
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{dbSetName}.SingleOrDefaultAsync({linqQuery});");
105107
method.AddIfStatement($"{Model.Name.ToCamelCase()} is not null", ifStatement =>
106108
{
107-
ifStatement.AddStatement($"_context.{Model.Name.Pluralize().ToPascalCase()}.Remove({Model.Name.ToCamelCase()});");
109+
ifStatement.AddStatement($"_context.{dbSetName}.Remove({Model.Name.ToCamelCase()});");
108110
});
109111
method.AddStatement("await _context.SaveChangesAsync();");
110112
method.AddStatement("return NoContent();", s => s.SeparatedFromPrevious());
@@ -123,7 +125,7 @@ public ODataAggregateControllerTemplate(IOutputTarget outputTarget, ClassModel m
123125
parameter.AddAttribute("[FromBody]");
124126
});
125127

126-
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{Model.Name.Pluralize().ToPascalCase()}.SingleOrDefaultAsync({linqQuery});");
128+
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{dbSetName}.SingleOrDefaultAsync({linqQuery});");
127129
method.AddIfStatement($"{Model.Name.ToCamelCase()} is null", ifStatement =>
128130
{
129131
ifStatement.AddStatement($"return NotFound();");
@@ -148,7 +150,7 @@ public ODataAggregateControllerTemplate(IOutputTarget outputTarget, ClassModel m
148150
parameter.AddAttribute("[FromBody]");
149151
});
150152

151-
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{Model.Name.Pluralize().ToPascalCase()}.AsNoTracking().SingleOrDefaultAsync({linqQuery});");
153+
method.AddStatement($"var {Model.Name.ToCamelCase()} = await _context.{dbSetName}.AsNoTracking().SingleOrDefaultAsync({linqQuery});");
152154
method.AddIfStatement($"{Model.Name.ToCamelCase()} is null", ifStatement =>
153155
{
154156
ifStatement.AddStatement($"return NotFound();");
@@ -209,5 +211,15 @@ public override string TransformText()
209211
{
210212
return CSharpFile.ToString();
211213
}
214+
215+
private string GetDbSetName(ClassModel model)
216+
{
217+
if (this.ExecutionContext.Settings.GetSetting("ac0a788e-d8b3-4eea-b56d-538608f1ded9", "6010e890-6e2d-4812-9969-ffbdb8f93d87")?.Value == "same-as-entity")
218+
{
219+
return model.Name.ToPascalCase();
220+
}
221+
222+
return model.Name.ToPascalCase().Pluralize();
223+
}
212224
}
213225
}

Modules/Intent.Modules.AspNetCore.OData.EntityFramework/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Version 1.0.7
2+
3+
- Improvement: Added support for singular DBSet names
4+
15
### Version 1.0.6
26

37
- Improvement: Updated topic documentation format.

Modules/Intent.Modules.EntityFrameworkCore.DiffAudit/FactoryExtensions/EfCoreExtension.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Linq;
21
using Intent.Engine;
32
using Intent.Exceptions;
43
using Intent.Modelers.Domain.Api;
@@ -14,6 +13,8 @@
1413
using Intent.Modules.EntityFrameworkCore.Shared;
1514
using Intent.Plugins.FactoryExtensions;
1615
using Intent.RoslynWeaver.Attributes;
16+
using Intent.Templates;
17+
using System.Linq;
1718

1819
[assembly: DefaultIntentManaged(Mode.Fully)]
1920
[assembly: IntentTemplate("Intent.ModuleBuilder.Templates.FactoryExtension", Version = "1.0")]
@@ -209,8 +210,20 @@ private static void AddChangeAuditingMethod(ICSharpFileBuilderTemplate template,
209210
.AddStatement("throw new ArgumentOutOfRangeException();")));
210211
});
211212

212-
method.AddStatement($"{logEntityName.Pluralize()}.AddRange(auditEntries);");
213+
214+
215+
method.AddStatement($"{GetDbSetName(template, logEntityName)}.AddRange(auditEntries);");
213216
});
214217
}
218+
219+
public static string GetDbSetName(ICSharpFileBuilderTemplate template, string logEntityName)
220+
{
221+
if (template.ExecutionContext.Settings.GetSetting("ac0a788e-d8b3-4eea-b56d-538608f1ded9", "6010e890-6e2d-4812-9969-ffbdb8f93d87")?.Value == "same-as-entity")
222+
{
223+
return logEntityName.ToPascalCase();
224+
}
225+
226+
return logEntityName.Pluralize();
227+
}
215228
}
216229
}

Modules/Intent.Modules.EntityFrameworkCore.DiffAudit/Intent.EntityFrameworkCore.DiffAudit.imodspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.EntityFrameworkCore.DiffAudit</id>
4-
<version>1.0.1</version>
4+
<version>1.0.2-pre.0</version>
55
<supportedClientVersions>[4.3.0-a,5.0.0)</supportedClientVersions>
66
<summary>Applies diff auditing to selected domain entities (i.e when an entity is created, modified or removed and by who).</summary>
77
<description>Applies diff auditing to selected domain entities (i.e when an entity is created, modified or removed and by who). Will store all log entries in a Audit log table.</description>

Modules/Intent.Modules.EntityFrameworkCore.DiffAudit/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Version 1.0.2
2+
3+
- Improvement: Added support for singular DBSet names
4+
15
### Version 1.0.1
26

37
- Improvement: Added stereotype descriptions in preperation for Intent Architect 4.5.

0 commit comments

Comments
 (0)