Skip to content

Commit

Permalink
add option to turn off temporal table mapping, add script template me…
Browse files Browse the repository at this point in the history
…rge, add rowversion options
  • Loading branch information
pwelter34 committed Jan 1, 2024
1 parent d57d802 commit 632a023
Show file tree
Hide file tree
Showing 41 changed files with 347 additions and 131 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ Entity Framework Core Generator supports generating [Read](https://efg.loresoft.

## Change Log

### Version 6.0

- upgrade to .net 8
- add option to turn off temporal table mapping
- add rowversion options, ByteArray|Long|ULong
- add script template merge

### Version 5.0

- add support for navigation property renames
Expand Down
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ data:
directory: '{Project.Directory}\Data\Mapping' # the mapping class output directory
#include XML documentation
document: false

temporal: false # if temporal table mapping is enabled. Default true
rowVersion: ByteArray|Long|ULong # How row versions should be mapped. Default ByteArray

# query extension class file configuration
query:
Expand Down Expand Up @@ -191,6 +194,7 @@ script:
namespace: '{Project.Namespace}.Domain.Context'
baseClass: ContextScriptBase
overwrite: true # overwrite existing file
merge: true # merge regions with existing file
# collection of script template with current Entity as a variable
entity:
- templatePath: '.\templates\entity.csx' # path to script file
Expand All @@ -199,6 +203,7 @@ script:
namespace: '{Project.Namespace}.Domain.Entity'
baseClass: EntityScriptBase
overwrite: true # overwrite existing file
merge: true # merge regions with existing file
# collection script template with current Model as a variable
model:
- templatePath: '.\templates\model.csx' # path to script file
Expand All @@ -207,10 +212,12 @@ script:
namespace: '{Project.Namespace}.Domain.Models'
baseClass: ModelScriptBase
overwrite: true # overwrite existing file
merge: true # merge regions with existing file
- templatePath: '.\templates\sample.csx' # path to script file
fileName: '{Model.Name}Sample.cs' # filename to save script output
directory: '{Project.Directory}\Domain\Models' # directory to save script output
namespace: '{Project.Namespace}.Domain.Models'
baseClass: ModelSampleBase
overwrite: true # overwrite existing file
merge: true # merge regions with existing file
```
1 change: 1 addition & 0 deletions sample/Tracker/Tracker.Core/Data/Mapping/AuditMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
6 changes: 4 additions & 2 deletions sample/Tracker/Tracker.Core/Data/Mapping/PriorityMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.DisplayOrder)
.IsRequired()
.HasColumnName("DisplayOrder")
.HasColumnType("int");
.HasColumnType("int")
.HasDefaultValue(0);

builder.Property(t => t.IsActive)
.IsRequired()
.HasColumnName("IsActive")
.HasColumnType("bit")
.HasDefaultValueSql("((1))");
.HasDefaultValue(true);

builder.Property(t => t.Created)
.IsRequired()
Expand All @@ -77,6 +78,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
1 change: 1 addition & 0 deletions sample/Tracker/Tracker.Core/Data/Mapping/RoleMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
6 changes: 4 additions & 2 deletions sample/Tracker/Tracker.Core/Data/Mapping/StatusMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.DisplayOrder)
.IsRequired()
.HasColumnName("DisplayOrder")
.HasColumnType("int");
.HasColumnType("int")
.HasDefaultValueSql("((0))");

builder.Property(t => t.IsActive)
.IsRequired()
.HasColumnName("IsActive")
.HasColumnType("bit")
.HasDefaultValueSql("((1))");
.HasDefaultValue(true);

builder.Property(t => t.Created)
.IsRequired()
Expand All @@ -77,6 +78,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
1 change: 1 addition & 0 deletions sample/Tracker/Tracker.Core/Data/Mapping/TaskMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
3 changes: 2 additions & 1 deletion sample/Tracker/Tracker.Core/Data/Mapping/TenantMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
.IsRequired()
.HasColumnName("IsActive")
.HasColumnType("bit")
.HasDefaultValueSql("((1))");
.HasDefaultValue(true);

builder.Property(t => t.Created)
.IsRequired()
Expand All @@ -71,6 +71,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
4 changes: 3 additions & 1 deletion sample/Tracker/Tracker.Core/Data/Mapping/UserLoginMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.IsSuccessful)
.IsRequired()
.HasColumnName("IsSuccessful")
.HasColumnType("bit");
.HasColumnType("bit")
.HasDefaultValue(false);

builder.Property(t => t.FailureMessage)
.HasColumnName("FailureMessage")
Expand Down Expand Up @@ -109,6 +110,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
13 changes: 9 additions & 4 deletions sample/Tracker/Tracker.Core/Data/Mapping/UserMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.IsEmailAddressConfirmed)
.IsRequired()
.HasColumnName("IsEmailAddressConfirmed")
.HasColumnType("bit");
.HasColumnType("bit")
.HasDefaultValue(false);

builder.Property(t => t.DisplayName)
.IsRequired()
Expand All @@ -62,12 +63,14 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.AccessFailedCount)
.IsRequired()
.HasColumnName("AccessFailedCount")
.HasColumnType("int");
.HasColumnType("int")
.HasDefaultValueSql("((0))");

builder.Property(t => t.LockoutEnabled)
.IsRequired()
.HasColumnName("LockoutEnabled")
.HasColumnType("bit");
.HasColumnType("bit")
.HasDefaultValue(false);

builder.Property(t => t.LockoutEnd)
.HasColumnName("LockoutEnd")
Expand All @@ -80,7 +83,8 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.IsDeleted)
.IsRequired()
.HasColumnName("IsDeleted")
.HasColumnType("bit");
.HasColumnType("bit")
.HasDefaultValue(false);

builder.Property(t => t.Created)
.IsRequired()
Expand All @@ -107,6 +111,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(t => t.RowVersion)
.IsRequired()
.IsRowVersion()
.IsConcurrencyToken()
.HasColumnName("RowVersion")
.HasColumnType("rowversion")
.HasMaxLength(8)
Expand Down
2 changes: 1 addition & 1 deletion sample/Tracker/Tracker.Core/Tracker.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="FluentValidation" Version="11.8.1" />
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion sample/Tracker/Tracker.Scaffold/Priority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class Priority

public int DisplayOrder { get; set; }

public bool? IsActive { get; set; }
public bool IsActive { get; set; }

public DateTimeOffset Created { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion sample/Tracker/Tracker.Scaffold/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class Status

public int DisplayOrder { get; set; }

public bool? IsActive { get; set; }
public bool IsActive { get; set; }

public DateTimeOffset Created { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion sample/Tracker/Tracker.Scaffold/Tenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class Tenant

public string? Description { get; set; }

public bool? IsActive { get; set; }
public bool IsActive { get; set; }

public DateTimeOffset Created { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
19 changes: 6 additions & 13 deletions sample/Tracker/Tracker.Scaffold/TrackerContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -36,7 +36,8 @@ public TrackerContext(DbContextOptions<TrackerContext> options)
public virtual DbSet<UserLogin> UserLogins { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer("Data Source=(local)\\sql2022;Initial Catalog=Tracker;Integrated Security=True;TrustServerCertificate=True");
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.

Check warning on line 39 in sample/Tracker/Tracker.Scaffold/TrackerContext.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.'

Check warning on line 39 in sample/Tracker/Tracker.Scaffold/TrackerContext.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.'
=> optionsBuilder.UseSqlServer("Data Source=(local);Initial Catalog=Tracker;Integrated Security=True;TrustServerCertificate=True");

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -64,9 +65,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.Created).HasDefaultValueSql("(sysutcdatetime())");
entity.Property(e => e.CreatedBy).HasMaxLength(100);
entity.Property(e => e.Description).HasMaxLength(255);
entity.Property(e => e.IsActive)
.IsRequired()
.HasDefaultValueSql("((1))");
entity.Property(e => e.IsActive).HasDefaultValue(true);
entity.Property(e => e.Name).HasMaxLength(100);
entity.Property(e => e.RowVersion)
.IsRowVersion()
Expand Down Expand Up @@ -108,9 +107,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.Created).HasDefaultValueSql("(sysutcdatetime())");
entity.Property(e => e.CreatedBy).HasMaxLength(100);
entity.Property(e => e.Description).HasMaxLength(255);
entity.Property(e => e.IsActive)
.IsRequired()
.HasDefaultValueSql("((1))");
entity.Property(e => e.IsActive).HasDefaultValue(true);
entity.Property(e => e.Name).HasMaxLength(100);
entity.Property(e => e.RowVersion)
.IsRowVersion()
Expand Down Expand Up @@ -152,8 +149,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.Updated).HasDefaultValueSql("(sysutcdatetime())");
entity.Property(e => e.UpdatedBy).HasMaxLength(100);



entity.HasOne(d => d.Assigned).WithMany(p => p.Tasks).HasForeignKey(d => d.AssignedId);

entity.HasOne(d => d.Priority).WithMany(p => p.Tasks).HasForeignKey(d => d.PriorityId);
Expand Down Expand Up @@ -196,9 +191,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.Id).HasDefaultValueSql("(newsequentialid())");
entity.Property(e => e.Created).HasDefaultValueSql("(sysutcdatetime())");
entity.Property(e => e.CreatedBy).HasMaxLength(100);
entity.Property(e => e.IsActive)
.IsRequired()
.HasDefaultValueSql("((1))");
entity.Property(e => e.IsActive).HasDefaultValue(true);
entity.Property(e => e.Name).HasMaxLength(256);
entity.Property(e => e.RowVersion)
.IsRowVersion()
Expand Down
1 change: 1 addition & 0 deletions sample/Tracker/Tracker.Scaffold/scaffold.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet ef dbcontext scaffold "Data Source=(local);Initial Catalog=Tracker;Integrated Security=True;TrustServerCertificate=True" Microsoft.EntityFrameworkCore.SqlServer --force
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AssemblyMetadata.Generators" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="AssemblyMetadata.Generators" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>EntityFrameworkCore.Generator</RootNamespace>
<NoWarn>1591,EF1001</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="7.21.12" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="7.21.12" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="8.21.121" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Data;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -36,6 +36,8 @@ public class Property : ModelBase

public bool? IsRowVersion { get; set; }

public bool? IsConcurrencyToken { get; set; }

public bool? IsUnique { get; set; }

[Obsolete("Value no longer used, will be deleted")]
Expand All @@ -49,7 +51,9 @@ public class Property : ModelBase
[Obsolete("Value no longer used, will be deleted")]
public int? Scale { get; set; }

public object DefaultValue { get; set; }

public string Default { get; set; }

public ValueGenerated? ValueGenerated { get; set; }
}
}
Loading

0 comments on commit 632a023

Please sign in to comment.