├── sample ├── Templates │ └── context-yaml.csx ├── TrackerSchema │ ├── TrackerSchema.Database │ │ ├── appsettings.json │ │ ├── TrackerSchema.Database.csproj │ │ └── Program.cs │ └── TrackerSchema.Core │ │ ├── TrackerSchema.Core.csproj │ │ └── Domain │ │ ├── Identity │ │ ├── Validation │ │ │ ├── IdentityUserRoleCreateModelValidator.cs │ │ │ ├── IdentityUserRoleUpdateModelValidator.cs │ │ │ ├── IdentityRoleCreateModelValidator.cs │ │ │ ├── IdentityRoleUpdateModelValidator.cs │ │ │ ├── IdentityUserCreateModelValidator.cs │ │ │ ├── IdentityUserUpdateModelValidator.cs │ │ │ ├── IdentityUserLoginCreateModelValidator.cs │ │ │ └── IdentityUserLoginUpdateModelValidator.cs │ │ ├── Models │ │ │ ├── IdentityUserRoleReadModel.cs │ │ │ ├── IdentityUserRoleCreateModel.cs │ │ │ └── IdentityUserRoleUpdateModel.cs │ │ └── Mapping │ │ │ ├── IdentityRoleProfile.cs │ │ │ ├── IdentityUserProfile.cs │ │ │ ├── IdentityUserRoleProfile.cs │ │ │ └── IdentityUserLoginProfile.cs │ │ └── Tracker │ │ ├── Validation │ │ ├── TrackerTaskCreateModelValidator.cs │ │ ├── TrackerTaskUpdateModelValidator.cs │ │ ├── TrackerAuditCreateModelValidator.cs │ │ ├── TrackerAuditUpdateModelValidator.cs │ │ ├── TrackerTaskExtendedCreateModelValidator.cs │ │ ├── TrackerTaskExtendedUpdateModelValidator.cs │ │ ├── TrackerStatusCreateModelValidator.cs │ │ ├── TrackerStatusUpdateModelValidator.cs │ │ ├── TrackerPriorityCreateModelValidator.cs │ │ └── TrackerPriorityUpdateModelValidator.cs │ │ └── Mapping │ │ ├── TrackerTaskProfile.cs │ │ ├── TrackerAuditProfile.cs │ │ ├── TrackerStatusProfile.cs │ │ ├── TrackerPriorityProfile.cs │ │ └── TrackerTaskExtendedProfile.cs ├── Tracker.PostgreSQL │ ├── Tracker.PostgreSQL.Database │ │ ├── appsettings.json │ │ ├── Tracker.PostgreSQL.Database.csproj │ │ └── Program.cs │ └── Tracker.PostgreSQL.Core │ │ ├── Domain │ │ ├── Models │ │ │ ├── UserRoleReadModel.cs │ │ │ ├── UserRoleCreateModel.cs │ │ │ ├── UserRoleUpdateModel.cs │ │ │ ├── RoleReadModel.cs │ │ │ ├── RoleCreateModel.cs │ │ │ ├── RoleUpdateModel.cs │ │ │ ├── TaskExtendedCreateModel.cs │ │ │ ├── TaskExtendedReadModel.cs │ │ │ ├── TaskExtendedUpdateModel.cs │ │ │ ├── StatusReadModel.cs │ │ │ ├── PriorityCreateModel.cs │ │ │ ├── PriorityReadModel.cs │ │ │ ├── PriorityUpdateModel.cs │ │ │ ├── StatusCreateModel.cs │ │ │ ├── StatusUpdateModel.cs │ │ │ ├── AuditReadModel.cs │ │ │ ├── AuditCreateModel.cs │ │ │ ├── AuditUpdateModel.cs │ │ │ ├── TaskReadModel.cs │ │ │ ├── TaskCreateModel.cs │ │ │ ├── TaskUpdateModel.cs │ │ │ ├── UserLoginReadModel.cs │ │ │ ├── UserLoginCreateModel.cs │ │ │ ├── UserLoginUpdateModel.cs │ │ │ ├── UserReadModel.cs │ │ │ ├── UserCreateModel.cs │ │ │ └── UserUpdateModel.cs │ │ ├── Validation │ │ │ ├── UserRoleCreateModelValidator.cs │ │ │ ├── UserRoleUpdateModelValidator.cs │ │ │ ├── RoleCreateModelValidator.cs │ │ │ ├── RoleUpdateModelValidator.cs │ │ │ ├── TaskCreateModelValidator.cs │ │ │ ├── TaskUpdateModelValidator.cs │ │ │ ├── TaskExtendedCreateModelValidator.cs │ │ │ ├── TaskExtendedUpdateModelValidator.cs │ │ │ ├── AuditCreateModelValidator.cs │ │ │ ├── AuditUpdateModelValidator.cs │ │ │ ├── StatusCreateModelValidator.cs │ │ │ ├── StatusUpdateModelValidator.cs │ │ │ ├── PriorityCreateModelValidator.cs │ │ │ ├── PriorityUpdateModelValidator.cs │ │ │ ├── UserCreateModelValidator.cs │ │ │ ├── UserUpdateModelValidator.cs │ │ │ ├── UserLoginCreateModelValidator.cs │ │ │ └── UserLoginUpdateModelValidator.cs │ │ └── Mapping │ │ │ ├── RoleProfile.cs │ │ │ ├── TaskProfile.cs │ │ │ ├── UserProfile.cs │ │ │ ├── AuditProfile.cs │ │ │ ├── StatusProfile.cs │ │ │ ├── PriorityProfile.cs │ │ │ ├── UserRoleProfile.cs │ │ │ ├── UserLoginProfile.cs │ │ │ └── TaskExtendedProfile.cs │ │ ├── Tracker.PostgreSQL.Core.csproj │ │ └── Data │ │ ├── Entities │ │ ├── UserRole.cs │ │ ├── Role.cs │ │ ├── TaskExtended.cs │ │ ├── Audit.cs │ │ ├── Status.cs │ │ ├── Priority.cs │ │ ├── UserLogin.cs │ │ └── Task.cs │ │ └── Queries │ │ ├── AuditExtensions.cs │ │ ├── StatusExtensions.cs │ │ ├── PriorityExtensions.cs │ │ └── TaskExtendedExtensions.cs ├── Tracker │ ├── Tracker.Core │ │ ├── Definitions │ │ │ ├── IHaveIdentifier.cs │ │ │ ├── ITrackDeleted.cs │ │ │ ├── ITrackConcurrency.cs │ │ │ ├── ITrackCreated.cs │ │ │ └── ITrackUpdated.cs │ │ ├── Tracker.Core.csproj │ │ └── Domain │ │ │ ├── EntityCreateModel.cs │ │ │ ├── EntityReadModel.cs │ │ │ ├── EntityUpdateModel.cs │ │ │ ├── UserRole │ │ │ ├── Validation │ │ │ │ ├── UserRoleCreateModelValidator.cs │ │ │ │ └── UserRoleUpdateModelValidator.cs │ │ │ ├── Mapping │ │ │ │ └── UserRoleProfile.cs │ │ │ └── Models │ │ │ │ ├── UserRoleReadModel.cs │ │ │ │ ├── UserRoleCreateModel.cs │ │ │ │ └── UserRoleUpdateModel.cs │ │ │ ├── Audit │ │ │ ├── Mapping │ │ │ │ └── AuditProfile.cs │ │ │ └── Validation │ │ │ │ ├── AuditCreateModelValidator.cs │ │ │ │ └── AuditUpdateModelValidator.cs │ │ │ ├── UserLogin │ │ │ └── Mapping │ │ │ │ └── UserLoginProfile.cs │ │ │ ├── Role │ │ │ ├── Validation │ │ │ │ ├── RoleCreateModelValidator.cs │ │ │ │ └── RoleUpdateModelValidator.cs │ │ │ ├── Models │ │ │ │ ├── RoleReadModel.cs │ │ │ │ ├── RoleCreateModel.cs │ │ │ │ └── RoleUpdateModel.cs │ │ │ └── Mapping │ │ │ │ └── RoleProfile.cs │ │ │ ├── Task │ │ │ ├── Validation │ │ │ │ ├── TaskCreateModelValidator.cs │ │ │ │ └── TaskUpdateModelValidator.cs │ │ │ └── Mapping │ │ │ │ └── TaskProfile.cs │ │ │ ├── Tenant │ │ │ ├── Validation │ │ │ │ ├── TenantCreateModelValidator.cs │ │ │ │ └── TenantUpdateModelValidator.cs │ │ │ ├── Mapping │ │ │ │ └── TenantProfile.cs │ │ │ └── Models │ │ │ │ ├── TenantReadModel.cs │ │ │ │ ├── TenantCreateModel.cs │ │ │ │ └── TenantUpdateModel.cs │ │ │ ├── TaskExtended │ │ │ ├── Validation │ │ │ │ ├── TaskExtendedCreateModelValidator.cs │ │ │ │ └── TaskExtendedUpdateModelValidator.cs │ │ │ └── Mapping │ │ │ │ └── TaskExtendedProfile.cs │ │ │ ├── Status │ │ │ ├── Validation │ │ │ │ ├── StatusCreateModelValidator.cs │ │ │ │ └── StatusUpdateModelValidator.cs │ │ │ ├── Mapping │ │ │ │ └── StatusProfile.cs │ │ │ └── Models │ │ │ │ ├── StatusReadModel.cs │ │ │ │ ├── StatusCreateModel.cs │ │ │ │ └── StatusUpdateModel.cs │ │ │ ├── Priority │ │ │ ├── Validation │ │ │ │ ├── PriorityCreateModelValidator.cs │ │ │ │ └── PriorityUpdateModelValidator.cs │ │ │ ├── Mapping │ │ │ │ └── PriorityProfile.cs │ │ │ └── Models │ │ │ │ └── PriorityReadModel.cs │ │ │ └── User │ │ │ ├── Validation │ │ │ ├── UserCreateModelValidator.cs │ │ │ └── UserUpdateModelValidator.cs │ │ │ └── Mapping │ │ │ └── UserProfile.cs │ └── Tracker.Web │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ ├── Controllers │ │ ├── StatusController.cs │ │ ├── PriorityController.cs │ │ ├── UserLoginController.cs │ │ ├── RoleController.cs │ │ ├── UserController.cs │ │ ├── TaskController.cs │ │ ├── AuditController.cs │ │ └── TenantController.cs │ │ ├── Program.cs │ │ ├── Tracker.Web.csproj │ │ └── Properties │ │ └── launchSettings.json ├── create-docker.cmd └── docker-compose.yml ├── logo.png ├── test └── EntityFrameworkCore.Generator.Core.Tests │ ├── appsettings.json │ ├── appsettings.appveyor.json │ ├── DatabaseCollection.cs │ ├── DatabaseTestBase.cs │ └── CodeGeneratorTests.cs ├── src ├── EntityFrameworkCore.Generator │ ├── Properties │ │ └── launchSettings.json │ ├── CommandBase.cs │ ├── OptionsCommandBase.cs │ └── EntityFrameworkCore.Generator.csproj └── EntityFrameworkCore.Generator.Core │ ├── Metadata │ ├── Generation │ │ ├── ModelType.cs │ │ ├── Cardinality.cs │ │ ├── CodeLanguage.cs │ │ ├── ModelBase.cs │ │ ├── EntityContext.cs │ │ ├── Method.cs │ │ ├── Model.cs │ │ └── Relationship.cs │ └── Parsing │ │ ├── CodeRegion.cs │ │ ├── ParsedEntitySet.cs │ │ ├── ParsedContext.cs │ │ ├── ParsedProperty.cs │ │ ├── ParsedEntity.cs │ │ └── ParsedRelationship.cs │ ├── ICodeGenerator.cs │ ├── VariableConstants.cs │ ├── Scripts │ ├── ModelScriptVariables.cs │ ├── EntityScriptVariables.cs │ ├── ContextScriptVariables.cs │ ├── ScriptVariablesBase.cs │ ├── ModelScriptTemplate.cs │ ├── EntityScriptTemplate.cs │ └── ContextScriptTemplate.cs │ ├── Options │ ├── EntityNaming.cs │ ├── ReadModelOptions.cs │ ├── TableNaming.cs │ ├── RelationshipNaming.cs │ ├── UpdateModelOptions.cs │ ├── ContextNaming.cs │ ├── DatabaseProviders.cs │ ├── CreateModelOptions.cs │ ├── MappingClassOptions.cs │ ├── SelectionOptions.cs │ ├── ScriptOptions.cs │ └── ProjectOptions.cs │ ├── IOptionVariable.cs │ └── Parsing │ └── RegionParser.cs ├── docs ├── providers.md ├── index.md └── md │ └── shared.md ├── mkdocs.yml ├── appveyor.yml └── LICENSE /sample/Templates/context-yaml.csx: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ualehosaini/EntityFrameworkCore.Generator/HEAD/logo.png -------------------------------------------------------------------------------- /test/EntityFrameworkCore.Generator.Core.Tests/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "Tracker": "Data Source=(local);Initial Catalog=TrackerTest;Integrated Security=True" 4 | } 5 | } -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Database/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "TrackerSchema": "Data Source=(local);Initial Catalog=TrackerSchema;Integrated Security=True" 4 | } 5 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Database/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "Tracker": "Server=ares;Port=5432;Database=Tracker;User Id=postgres;Password=!p@ssword;" 4 | } 5 | } -------------------------------------------------------------------------------- /test/EntityFrameworkCore.Generator.Core.Tests/appsettings.appveyor.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "Tracker": "Server=(local)\\SQL2017;Database=TrackerAppVeyor;Integrated security=SSPI;" 4 | } 5 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Definitions/IHaveIdentifier.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Tracker.Core.Definitions 4 | { 5 | public interface IHaveIdentifier 6 | { 7 | Guid Id { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /sample/create-docker.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=!p@ssword -d postgres:latest 4 | docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=!p@ssword -d mysql:latest -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Definitions/ITrackDeleted.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Tracker.Core.Definitions 4 | { 5 | public interface ITrackDeleted 6 | { 7 | bool IsDeleted { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "EntityFrameworkCore.Generator": { 4 | "commandName": "Project", 5 | "commandLineArgs": "init" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Definitions/ITrackConcurrency.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Tracker.Core.Definitions 4 | { 5 | public interface ITrackConcurrency 6 | { 7 | string RowVersion { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/ModelType.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFrameworkCore.Generator.Metadata.Generation 2 | { 3 | public enum ModelType 4 | { 5 | Read, 6 | Create, 7 | Update 8 | } 9 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Definitions/ITrackCreated.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Tracker.Core.Definitions 4 | { 5 | public interface ITrackCreated 6 | { 7 | DateTimeOffset Created { get; set; } 8 | string CreatedBy { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Definitions/ITrackUpdated.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Tracker.Core.Definitions 4 | { 5 | public interface ITrackUpdated 6 | { 7 | DateTimeOffset Updated { get; set; } 8 | string UpdatedBy { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Cardinality.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Metadata.Generation 4 | { 5 | public enum Cardinality 6 | { 7 | ZeroOrOne, 8 | One, 9 | Many 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/ICodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EntityFrameworkCore.Generator.Options; 3 | 4 | namespace EntityFrameworkCore.Generator 5 | { 6 | public interface ICodeGenerator 7 | { 8 | bool Generate(GeneratorOptions options); 9 | } 10 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "ConnectionStrings": { 8 | "Tracker": "Data Source=(local);Initial Catalog=Tracker;Integrated Security=True" 9 | }, 10 | "AllowedHosts": "*" 11 | } 12 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/CodeLanguage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace EntityFrameworkCore.Generator.Metadata.Generation 6 | { 7 | public enum CodeLanguage 8 | { 9 | CSharp, 10 | VisualBasic 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/EntityFrameworkCore.Generator.Core.Tests/DatabaseCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | 4 | namespace FluentCommand.SqlServer.Tests 5 | { 6 | [CollectionDefinition(DatabaseCollection.CollectionName)] 7 | public class DatabaseCollection : ICollectionFixture 8 | { 9 | public const string CollectionName = "DatabaseCollection"; 10 | } 11 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Parsing/CodeRegion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Metadata.Parsing 4 | { 5 | public class CodeRegion 6 | { 7 | public int StartIndex { get; set; } 8 | public int EndIndex { get; set; } 9 | public string Name { get; set; } 10 | public string Content { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/VariableConstants.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFrameworkCore.Generator 2 | { 3 | public static class VariableConstants 4 | { 5 | public const string TableSchema = "Table.Schema"; 6 | public const string TableName = "Table.Name"; 7 | public const string EntityName = "Entity.Name"; 8 | public const string ModelName = "Model.Name"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Parsing/ParsedEntitySet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace EntityFrameworkCore.Generator.Metadata.Parsing 5 | { 6 | [DebuggerDisplay("Entity: {EntityClass}, Property: {ContextProperty}")] 7 | public class ParsedEntitySet 8 | { 9 | public string EntityClass { get; set; } 10 | public string ContextProperty { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserRoleReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserRoleReadModel 7 | { 8 | #region Generated Properties 9 | public Guid UserId { get; set; } 10 | 11 | public Guid RoleId { get; set; } 12 | 13 | #endregion 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserRoleCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserRoleCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid UserId { get; set; } 10 | 11 | public Guid RoleId { get; set; } 12 | 13 | #endregion 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserRoleUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserRoleUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid UserId { get; set; } 10 | 11 | public Guid RoleId { get; set; } 12 | 13 | #endregion 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/StatusController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Tracker.Core.Data; 3 | using Tracker.Core.Domain.Models; 4 | 5 | namespace Tracker.Web.Controllers 6 | { 7 | public class StatusController : QueryControllerBase 8 | { 9 | public StatusController(TrackerContext dataContext, IMapper mapper) : base(dataContext, mapper) 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/PriorityController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Tracker.Core.Data; 3 | using Tracker.Core.Domain.Models; 4 | 5 | namespace Tracker.Web.Controllers 6 | { 7 | public class PriorityController : QueryControllerBase 8 | { 9 | public PriorityController(TrackerContext dataContext, IMapper mapper) : base(dataContext, mapper) 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/UserLoginController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Tracker.Core.Data; 3 | using Tracker.Core.Domain.Models; 4 | 5 | namespace Tracker.Web.Controllers 6 | { 7 | public class UserLoginController : QueryControllerBase 8 | { 9 | public UserLoginController(TrackerContext dataContext, IMapper mapper) : base(dataContext, mapper) 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/TrackerSchema.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | 5 | postgres: 6 | image: postgres:latest 7 | container_name: postgres 8 | restart: always 9 | environment: 10 | POSTGRES_PASSWORD: "!p@ssword" 11 | ports: 12 | - "5432:5432" 13 | 14 | mysql: 15 | image: mysql:latest 16 | container_name: mysql 17 | command: --default-authentication-plugin=mysql_native_password 18 | restart: always 19 | environment: 20 | MYSQL_ROOT_PASSWORD: "!p@ssword" 21 | 22 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/UserRoleCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class UserRoleCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public UserRoleCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | #endregion 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/UserRoleUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class UserRoleUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public UserRoleUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | #endregion 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Tracker.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Parsing/ParsedContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace EntityFrameworkCore.Generator.Metadata.Parsing 6 | { 7 | [DebuggerDisplay("Context: {ContextClass}")] 8 | public class ParsedContext 9 | { 10 | public ParsedContext() 11 | { 12 | Properties = new List(); 13 | } 14 | 15 | public string ContextClass { get; set; } 16 | 17 | public List Properties { get; } 18 | } 19 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/EntityCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Tracker.Core.Definitions; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | public class EntityCreateModel : IHaveIdentifier, ITrackCreated, ITrackUpdated 8 | { 9 | public Guid Id { get; set; } 10 | 11 | public DateTimeOffset Created { get; set; } 12 | 13 | public string CreatedBy { get; set; } 14 | 15 | public DateTimeOffset Updated { get; set; } 16 | 17 | public string UpdatedBy { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/ModelScriptVariables.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Metadata.Generation; 2 | using EntityFrameworkCore.Generator.Options; 3 | 4 | namespace EntityFrameworkCore.Generator.Scripts 5 | { 6 | public class ModelScriptVariables : ScriptVariablesBase 7 | { 8 | public ModelScriptVariables(Model model, GeneratorOptions generatorOptions, TemplateOptions templateOptions) 9 | : base(generatorOptions, templateOptions) 10 | { 11 | Model = model; 12 | } 13 | 14 | public Model Model { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Parsing/ParsedProperty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace EntityFrameworkCore.Generator.Metadata.Parsing 5 | { 6 | [DebuggerDisplay("Column: {ColumnName}, Property: {PropertyName}")] 7 | public class ParsedProperty 8 | { 9 | public string ColumnName { get; set; } 10 | public string PropertyName { get; set; } 11 | 12 | public bool IsValid() 13 | { 14 | return !string.IsNullOrEmpty(ColumnName) 15 | && !string.IsNullOrEmpty(PropertyName); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/EntityScriptVariables.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Metadata.Generation; 2 | using EntityFrameworkCore.Generator.Options; 3 | 4 | namespace EntityFrameworkCore.Generator.Scripts 5 | { 6 | public class EntityScriptVariables : ScriptVariablesBase 7 | { 8 | public EntityScriptVariables(Entity entity, GeneratorOptions generatorOptions, TemplateOptions templateOptions) 9 | : base(generatorOptions, templateOptions) 10 | { 11 | Entity = entity; 12 | } 13 | 14 | public Entity Entity { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Hosting; 3 | 4 | namespace Tracker.Web 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | CreateHostBuilder(args).Build().Run(); 11 | } 12 | 13 | public static IHostBuilder CreateHostBuilder(string[] args) => 14 | Host.CreateDefaultBuilder(args) 15 | .ConfigureWebHostDefaults(webBuilder => 16 | { 17 | webBuilder.UseStartup(); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/RoleController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using FluentValidation; 3 | using Tracker.Core.Data; 4 | using Tracker.Core.Domain.Models; 5 | 6 | namespace Tracker.Web.Controllers 7 | { 8 | public class RoleController : EntityControllerBase 9 | { 10 | public RoleController(TrackerContext dataContext, IMapper mapper, IValidator createValidator, IValidator updateValidator) 11 | : base(dataContext, mapper, createValidator, updateValidator) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using FluentValidation; 3 | using Tracker.Core.Data; 4 | using Tracker.Core.Domain.Models; 5 | 6 | namespace Tracker.Web.Controllers 7 | { 8 | public class UserController : EntityControllerBase 9 | { 10 | public UserController(TrackerContext dataContext, IMapper mapper, IValidator createValidator, IValidator updateValidator) 11 | : base(dataContext, mapper, createValidator, updateValidator) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/TaskController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using FluentValidation; 3 | using Tracker.Core.Data; 4 | using Tracker.Core.Domain.Models; 5 | 6 | namespace Tracker.Web.Controllers 7 | { 8 | public class TaskController : EntityControllerBase 9 | { 10 | public TaskController(TrackerContext dataContext, IMapper mapper, IValidator createValidator, IValidator updateValidator) 11 | : base(dataContext, mapper, createValidator, updateValidator) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/ModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Metadata.Generation 4 | { 5 | 6 | /// 7 | /// A base class for entity generation models 8 | /// 9 | public class ModelBase 10 | { 11 | 12 | /// 13 | /// Gets or sets a value indicating whether this instance is processed. 14 | /// 15 | /// 16 | /// true if this instance is processed; otherwise, false. 17 | /// 18 | public bool IsProcessed { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/AuditController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using FluentValidation; 3 | using Tracker.Core.Data; 4 | using Tracker.Core.Domain.Models; 5 | 6 | namespace Tracker.Web.Controllers 7 | { 8 | public class AuditController : EntityControllerBase 9 | { 10 | public AuditController(TrackerContext dataContext, IMapper mapper, IValidator createValidator, IValidator updateValidator) 11 | : base(dataContext, mapper, createValidator, updateValidator) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Controllers/TenantController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using FluentValidation; 3 | using Tracker.Core.Data; 4 | using Tracker.Core.Domain.Models; 5 | 6 | namespace Tracker.Web.Controllers 7 | { 8 | public class TenantController : EntityControllerBase 9 | { 10 | public TenantController(TrackerContext dataContext, IMapper mapper, IValidator createValidator, IValidator updateValidator) 11 | : base(dataContext, mapper, createValidator, updateValidator) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/ContextScriptVariables.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Metadata.Generation; 2 | using EntityFrameworkCore.Generator.Options; 3 | 4 | namespace EntityFrameworkCore.Generator.Scripts 5 | { 6 | public class ContextScriptVariables : ScriptVariablesBase 7 | { 8 | public ContextScriptVariables(EntityContext entityContext, GeneratorOptions generatorOptions, TemplateOptions templateOptions) 9 | : base(generatorOptions, templateOptions) 10 | { 11 | EntityContext = entityContext; 12 | } 13 | 14 | public EntityContext EntityContext { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/EntityNaming.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// Entity class naming strategy 7 | /// 8 | public enum EntityNaming 9 | { 10 | /// 11 | /// Use table name as entity name 12 | /// 13 | Preserve = 0, 14 | 15 | /// 16 | /// Use table name in plural form 17 | /// 18 | Plural = 1, 19 | 20 | /// 21 | /// Use table name in singular form 22 | /// 23 | Singular = 2 24 | } 25 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Tracker.PostgreSQL.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/ReadModelOptions.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFrameworkCore.Generator.Options 2 | { 3 | /// 4 | /// Read model options 5 | /// 6 | /// 7 | public class ReadModelOptions : ModelOptionsBase 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | public ReadModelOptions(VariableDictionary variables, string prefix) 13 | : base(variables, AppendPrefix(prefix, "Read")) 14 | { 15 | Name = "{Entity.Name}ReadModel"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/TableNaming.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// Table naming hint for how database tables are named. 7 | /// 8 | public enum TableNaming 9 | { 10 | /// 11 | /// Mix of Plural and Singular 12 | /// 13 | Mixed = 0, 14 | 15 | /// 16 | /// Tables are named in plural form 17 | /// 18 | Plural = 1, 19 | 20 | /// 21 | /// Tables are named in singular form 22 | /// 23 | Singular = 2 24 | } 25 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator/CommandBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using McMaster.Extensions.CommandLineUtils; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace EntityFrameworkCore.Generator 6 | { 7 | [HelpOption("--help")] 8 | public abstract class CommandBase 9 | { 10 | protected CommandBase(ILoggerFactory logger, IConsole console) 11 | { 12 | Logger = logger.CreateLogger(GetType()); 13 | Console = console; 14 | } 15 | 16 | protected ILogger Logger { get; } 17 | 18 | protected IConsole Console { get; } 19 | 20 | protected abstract int OnExecute(CommandLineApplication application); 21 | } 22 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/EntityReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Tracker.Core.Definitions; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | public class EntityReadModel : IHaveIdentifier, ITrackCreated, ITrackUpdated, ITrackConcurrency 8 | { 9 | public Guid Id { get; set; } 10 | 11 | public DateTimeOffset Created { get; set; } = DateTimeOffset.UtcNow; 12 | 13 | public string CreatedBy { get; set; } 14 | 15 | public DateTimeOffset Updated { get; set; } = DateTimeOffset.UtcNow; 16 | 17 | public string UpdatedBy { get; set; } 18 | 19 | public string RowVersion { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/EntityUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Tracker.Core.Definitions; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | public class EntityUpdateModel : IHaveIdentifier, ITrackCreated, ITrackUpdated, ITrackConcurrency 8 | { 9 | public Guid Id { get; set; } 10 | 11 | public DateTimeOffset Created { get; set; } = DateTimeOffset.UtcNow; 12 | 13 | public string CreatedBy { get; set; } 14 | 15 | public DateTimeOffset Updated { get; set; } = DateTimeOffset.UtcNow; 16 | 17 | public string UpdatedBy { get; set; } 18 | 19 | public string RowVersion { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/RelationshipNaming.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFrameworkCore.Generator.Options 2 | { 3 | /// 4 | /// Relationship property naming strategy 5 | /// 6 | public enum RelationshipNaming 7 | { 8 | /// 9 | /// Preserve property name as the entity name 10 | /// 11 | Preserve = 0, 12 | 13 | /// 14 | /// Convert the property name to the entity plural name 15 | /// 16 | Plural = 1, 17 | 18 | /// 19 | /// Add 'List' to the end of the entity name. 20 | /// 21 | Suffix = 2 22 | } 23 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/UpdateModelOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// Update model options 7 | /// 8 | /// 9 | public class UpdateModelOptions : ModelOptionsBase 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public UpdateModelOptions(VariableDictionary variables, string prefix) 15 | : base(variables, AppendPrefix(prefix, "Update")) 16 | { 17 | Name = "{Entity.Name}UpdateModel"; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/UserRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class UserRole 7 | { 8 | public UserRole() 9 | { 10 | #region Generated Constructor 11 | #endregion 12 | } 13 | 14 | #region Generated Properties 15 | public Guid UserId { get; set; } 16 | 17 | public Guid RoleId { get; set; } 18 | 19 | #endregion 20 | 21 | #region Generated Relationships 22 | public virtual Role Role { get; set; } 23 | 24 | public virtual User User { get; set; } 25 | 26 | #endregion 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/RoleCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class RoleCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public RoleCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MaximumLength(256); 15 | RuleFor(p => p.CreatedBy).MaximumLength(100); 16 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 17 | #endregion 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/RoleUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class RoleUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public RoleUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MaximumLength(256); 15 | RuleFor(p => p.CreatedBy).MaximumLength(100); 16 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 17 | #endregion 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/TaskCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class TaskCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public TaskCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Title).NotEmpty(); 14 | RuleFor(p => p.Title).MaximumLength(255); 15 | RuleFor(p => p.CreatedBy).MaximumLength(100); 16 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 17 | #endregion 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/TaskUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class TaskUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public TaskUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Title).NotEmpty(); 14 | RuleFor(p => p.Title).MaximumLength(255); 15 | RuleFor(p => p.CreatedBy).MaximumLength(100); 16 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 17 | #endregion 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/IOptionVariable.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFrameworkCore.Generator 2 | { 3 | /// 4 | /// 5 | /// 6 | public interface IOptionVariable 7 | { 8 | /// 9 | /// Sets variables on the specified VariableDictionary. 10 | /// 11 | /// The variable dictionary. 12 | void Set(VariableDictionary variableDictionary); 13 | 14 | /// 15 | /// Removes variables on the specified VariableDictionary. 16 | /// 17 | /// The variable dictionary. 18 | void Remove(VariableDictionary variableDictionary); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/ContextNaming.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// Naming strategies for entity data set property on the generated 7 | /// 8 | public enum ContextNaming 9 | { 10 | /// 11 | /// Preserve the entity name as is 12 | /// 13 | Preserve = 0, 14 | 15 | /// 16 | /// Convert the entity to plural form 17 | /// 18 | Plural = 1, 19 | 20 | /// 21 | /// Add 'DataSet' to the end of the entity name. 22 | /// 23 | Suffix = 2 24 | } 25 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/DatabaseProviders.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// The database to generate code for 7 | /// 8 | public enum DatabaseProviders 9 | { 10 | /// 11 | /// The SQL server provider 12 | /// 13 | SqlServer, 14 | 15 | /// 16 | /// The PostgreSQL provider 17 | /// 18 | PostgreSQL, 19 | 20 | /// 21 | /// The MySQL provider 22 | /// 23 | MySQL, 24 | 25 | /// 26 | /// The sqlite provider 27 | /// 28 | Sqlite 29 | } 30 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/RoleReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class RoleReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public DateTime Created { get; set; } 16 | 17 | public string CreatedBy { get; set; } 18 | 19 | public DateTime Updated { get; set; } 20 | 21 | public string UpdatedBy { get; set; } 22 | 23 | public Byte[] RowVersion { get; set; } 24 | 25 | #endregion 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/RoleCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class RoleCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public DateTime Created { get; set; } 16 | 17 | public string CreatedBy { get; set; } 18 | 19 | public DateTime Updated { get; set; } 20 | 21 | public string UpdatedBy { get; set; } 22 | 23 | public Byte[] RowVersion { get; set; } 24 | 25 | #endregion 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/RoleUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class RoleUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public DateTime Created { get; set; } 16 | 17 | public string CreatedBy { get; set; } 18 | 19 | public DateTime Updated { get; set; } 20 | 21 | public string UpdatedBy { get; set; } 22 | 23 | public Byte[] RowVersion { get; set; } 24 | 25 | #endregion 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Tracker.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 984ef0cf-2b22-4fd1-876d-e01499da4c1f 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/EntityContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace EntityFrameworkCore.Generator.Metadata.Generation 5 | { 6 | [DebuggerDisplay("Class: {ContextClass}, Database: {DatabaseName}")] 7 | public class EntityContext : ModelBase 8 | { 9 | public EntityContext() 10 | { 11 | Entities = new EntityCollection(); 12 | } 13 | 14 | public string ContextNamespace { get; set; } 15 | 16 | public string ContextClass { get; set; } 17 | 18 | public string ContextBaseClass { get; set; } 19 | 20 | public string DatabaseName { get; set; } 21 | 22 | public EntityCollection Entities { get; set; } 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/CreateModelOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// Create model file generation options 7 | /// 8 | /// 9 | public class CreateModelOptions : ModelOptionsBase 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public CreateModelOptions(VariableDictionary variables, string prefix) 15 | : base(variables, AppendPrefix(prefix, "Create")) 16 | { 17 | Name = "{Entity.Name}CreateModel"; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /test/EntityFrameworkCore.Generator.Core.Tests/DatabaseTestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.SqlClient; 3 | using Xunit; 4 | using Xunit.Abstractions; 5 | 6 | namespace FluentCommand.SqlServer.Tests 7 | { 8 | [Collection(DatabaseCollection.CollectionName)] 9 | public abstract class DatabaseTestBase : IDisposable 10 | { 11 | protected DatabaseTestBase(ITestOutputHelper output, DatabaseFixture databaseFixture) 12 | { 13 | Output = output; 14 | Database = databaseFixture; 15 | } 16 | 17 | 18 | public ITestOutputHelper Output { get; } 19 | 20 | public DatabaseFixture Database { get; } 21 | 22 | public void Dispose() 23 | { 24 | Database?.Report(Output); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/ScriptVariablesBase.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Options; 2 | using Microsoft.EntityFrameworkCore.Infrastructure; 3 | 4 | namespace EntityFrameworkCore.Generator.Scripts 5 | { 6 | public abstract class ScriptVariablesBase 7 | { 8 | protected ScriptVariablesBase(GeneratorOptions generatorOptions, TemplateOptions templateOptions) 9 | { 10 | GeneratorOptions = generatorOptions; 11 | TemplateOptions = templateOptions; 12 | CodeBuilder = new IndentedStringBuilder(); 13 | } 14 | 15 | public TemplateOptions TemplateOptions { get; } 16 | 17 | public GeneratorOptions GeneratorOptions { get; } 18 | 19 | public IndentedStringBuilder CodeBuilder { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/TaskExtendedCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class TaskExtendedCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public TaskExtendedCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Browser).MaximumLength(256); 14 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 15 | RuleFor(p => p.CreatedBy).MaximumLength(100); 16 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 17 | #endregion 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/TaskExtendedUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class TaskExtendedUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public TaskExtendedUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Browser).MaximumLength(256); 14 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 15 | RuleFor(p => p.CreatedBy).MaximumLength(100); 16 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 17 | #endregion 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/AuditCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class AuditCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public AuditCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Content).NotEmpty(); 14 | RuleFor(p => p.Username).NotEmpty(); 15 | RuleFor(p => p.Username).MaximumLength(50); 16 | RuleFor(p => p.CreatedBy).MaximumLength(100); 17 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 18 | #endregion 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/AuditUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class AuditUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public AuditUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Content).NotEmpty(); 14 | RuleFor(p => p.Username).NotEmpty(); 15 | RuleFor(p => p.Username).MaximumLength(50); 16 | RuleFor(p => p.CreatedBy).MaximumLength(100); 17 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 18 | #endregion 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserRole/Validation/UserRoleCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class UserRoleCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public UserRoleCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | #endregion 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserRole/Validation/UserRoleUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class UserRoleUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public UserRoleUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | #endregion 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/MappingClassOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | /// 6 | /// EntityFramework mapping class generation options 7 | /// 8 | /// 9 | public class MappingClassOptions : ClassOptionsBase 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public MappingClassOptions(VariableDictionary variables, string prefix) 15 | : base(variables, AppendPrefix(prefix, "Mapping")) 16 | { 17 | Namespace = "{Project.Namespace}.Data.Mapping"; 18 | Directory = @"{Project.Directory}\Data\Mapping"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/StatusCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class StatusCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public StatusCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MaximumLength(100); 15 | RuleFor(p => p.Description).MaximumLength(255); 16 | RuleFor(p => p.CreatedBy).MaximumLength(100); 17 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 18 | #endregion 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/StatusUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class StatusUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public StatusUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MaximumLength(100); 15 | RuleFor(p => p.Description).MaximumLength(255); 16 | RuleFor(p => p.CreatedBy).MaximumLength(100); 17 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 18 | #endregion 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Audit/Mapping/AuditProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class AuditProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public AuditProfile() 19 | { 20 | CreateMap(); 21 | CreateMap(); 22 | CreateMap(); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/PriorityCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class PriorityCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public PriorityCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MaximumLength(100); 15 | RuleFor(p => p.Description).MaximumLength(255); 16 | RuleFor(p => p.CreatedBy).MaximumLength(100); 17 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 18 | #endregion 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/PriorityUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class PriorityUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public PriorityUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.Name).NotEmpty(); 14 | RuleFor(p => p.Name).MaximumLength(100); 15 | RuleFor(p => p.Description).MaximumLength(255); 16 | RuleFor(p => p.CreatedBy).MaximumLength(100); 17 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 18 | #endregion 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/TaskExtendedCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class TaskExtendedCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid TaskId { get; set; } 10 | 11 | public string UserAgent { get; set; } 12 | 13 | public string Browser { get; set; } 14 | 15 | public string OperatingSystem { get; set; } 16 | 17 | public DateTime Created { get; set; } 18 | 19 | public string CreatedBy { get; set; } 20 | 21 | public DateTime Updated { get; set; } 22 | 23 | public string UpdatedBy { get; set; } 24 | 25 | public Byte[] RowVersion { get; set; } 26 | 27 | #endregion 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/TaskExtendedReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class TaskExtendedReadModel 7 | { 8 | #region Generated Properties 9 | public Guid TaskId { get; set; } 10 | 11 | public string UserAgent { get; set; } 12 | 13 | public string Browser { get; set; } 14 | 15 | public string OperatingSystem { get; set; } 16 | 17 | public DateTime Created { get; set; } 18 | 19 | public string CreatedBy { get; set; } 20 | 21 | public DateTime Updated { get; set; } 22 | 23 | public string UpdatedBy { get; set; } 24 | 25 | public Byte[] RowVersion { get; set; } 26 | 27 | #endregion 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/TaskExtendedUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class TaskExtendedUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid TaskId { get; set; } 10 | 11 | public string UserAgent { get; set; } 12 | 13 | public string Browser { get; set; } 14 | 15 | public string OperatingSystem { get; set; } 16 | 17 | public DateTime Created { get; set; } 18 | 19 | public string CreatedBy { get; set; } 20 | 21 | public DateTime Updated { get; set; } 22 | 23 | public string UpdatedBy { get; set; } 24 | 25 | public Byte[] RowVersion { get; set; } 26 | 27 | #endregion 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Database/TrackerSchema.Database.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | PreserveNewest 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Method.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace EntityFrameworkCore.Generator.Metadata.Generation 6 | { 7 | [DebuggerDisplay("Suffix: {NameSuffix}, IsKey: {IsKey}, IsUnique: {IsUnique}")] 8 | public class Method : ModelBase 9 | { 10 | public Method() 11 | { 12 | Properties = new PropertyCollection(); 13 | } 14 | 15 | public Entity Entity { get; set; } 16 | 17 | public string NameSuffix { get; set; } 18 | public string SourceName { get; set; } 19 | 20 | public bool IsKey { get; set; } 21 | public bool IsUnique { get; set; } 22 | public bool IsIndex { get; set; } 23 | 24 | public PropertyCollection Properties { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserLogin/Mapping/UserLoginProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class UserLoginProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public UserLoginProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserRole/Mapping/UserRoleProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class UserRoleProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public UserRoleProfile() 19 | { 20 | CreateMap(); 21 | CreateMap(); 22 | CreateMap(); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityUserRoleCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityUserRoleCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityUserRoleCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | #endregion 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityUserRoleUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityUserRoleUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityUserRoleUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | #endregion 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/StatusReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class StatusReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public int DisplayOrder { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public DateTime Created { get; set; } 20 | 21 | public string CreatedBy { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public string UpdatedBy { get; set; } 26 | 27 | public Byte[] RowVersion { get; set; } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/PriorityCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class PriorityCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public int DisplayOrder { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public DateTime Created { get; set; } 20 | 21 | public string CreatedBy { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public string UpdatedBy { get; set; } 26 | 27 | public Byte[] RowVersion { get; set; } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/PriorityReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class PriorityReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public int DisplayOrder { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public DateTime Created { get; set; } 20 | 21 | public string CreatedBy { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public string UpdatedBy { get; set; } 26 | 27 | public Byte[] RowVersion { get; set; } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/PriorityUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class PriorityUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public int DisplayOrder { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public DateTime Created { get; set; } 20 | 21 | public string CreatedBy { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public string UpdatedBy { get; set; } 26 | 27 | public Byte[] RowVersion { get; set; } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/StatusCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class StatusCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public int DisplayOrder { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public DateTime Created { get; set; } 20 | 21 | public string CreatedBy { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public string UpdatedBy { get; set; } 26 | 27 | public Byte[] RowVersion { get; set; } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/StatusUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class StatusUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public int DisplayOrder { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public DateTime Created { get; set; } 20 | 21 | public string CreatedBy { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public string UpdatedBy { get; set; } 26 | 27 | public Byte[] RowVersion { get; set; } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/UserCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class UserCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public UserCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.EmailAddress).NotEmpty(); 14 | RuleFor(p => p.EmailAddress).MaximumLength(256); 15 | RuleFor(p => p.DisplayName).NotEmpty(); 16 | RuleFor(p => p.DisplayName).MaximumLength(256); 17 | RuleFor(p => p.CreatedBy).MaximumLength(100); 18 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 19 | #endregion 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/UserUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class UserUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public UserUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.EmailAddress).NotEmpty(); 14 | RuleFor(p => p.EmailAddress).MaximumLength(256); 15 | RuleFor(p => p.DisplayName).NotEmpty(); 16 | RuleFor(p => p.DisplayName).MaximumLength(256); 17 | RuleFor(p => p.CreatedBy).MaximumLength(100); 18 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 19 | #endregion 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Role/Validation/RoleCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class RoleCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public RoleCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Name).NotEmpty(); 21 | RuleFor(p => p.Name).MaximumLength(256); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Role/Validation/RoleUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class RoleUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public RoleUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Name).NotEmpty(); 21 | RuleFor(p => p.Name).MaximumLength(256); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Task/Validation/TaskCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class TaskCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TaskCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Title).NotEmpty(); 21 | RuleFor(p => p.Title).MaximumLength(255); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Task/Validation/TaskUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class TaskUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TaskUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Title).NotEmpty(); 21 | RuleFor(p => p.Title).MaximumLength(255); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/AuditReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class AuditReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public DateTime Date { get; set; } 12 | 13 | public Guid? UserId { get; set; } 14 | 15 | public Guid? TaskId { get; set; } 16 | 17 | public string Content { get; set; } 18 | 19 | public string Username { get; set; } 20 | 21 | public DateTime Created { get; set; } 22 | 23 | public string CreatedBy { get; set; } 24 | 25 | public DateTime Updated { get; set; } 26 | 27 | public string UpdatedBy { get; set; } 28 | 29 | public Byte[] RowVersion { get; set; } 30 | 31 | #endregion 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /docs/providers.md: -------------------------------------------------------------------------------- 1 | # Database Providers 2 | 3 | Entity Framework Core Generator (efg) supports the following databases. 4 | 5 | * SQL Server 6 | * PostgreSQL 7 | * MySQL 8 | * Sqlite 9 | 10 | ## Database Schema 11 | 12 | The database schema is loaded from the Entity Framework Core database metadata model factory implementation of `IDatabaseModelFactory`. Entity Framework Core Generator used the the implemented interface from each of the supported providers similar to how `ef dbcontext scaffold` works. 13 | 14 | ## Usage 15 | 16 | The provider can be set via command line or via the [configuration file](configuration.md). 17 | 18 | Set via command line 19 | 20 | ```Shell 21 | efg generate -c -p 22 | ``` 23 | 24 | Set in configuration file 25 | 26 | ```YAML 27 | database: 28 | connectionString: 'Data Source=(local);Initial Catalog=Tracker;Integrated Security=True' 29 | provider: SqlServer 30 | ``` -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/AuditCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class AuditCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public DateTime Date { get; set; } 12 | 13 | public Guid? UserId { get; set; } 14 | 15 | public Guid? TaskId { get; set; } 16 | 17 | public string Content { get; set; } 18 | 19 | public string Username { get; set; } 20 | 21 | public DateTime Created { get; set; } 22 | 23 | public string CreatedBy { get; set; } 24 | 25 | public DateTime Updated { get; set; } 26 | 27 | public string UpdatedBy { get; set; } 28 | 29 | public Byte[] RowVersion { get; set; } 30 | 31 | #endregion 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/AuditUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class AuditUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public DateTime Date { get; set; } 12 | 13 | public Guid? UserId { get; set; } 14 | 15 | public Guid? TaskId { get; set; } 16 | 17 | public string Content { get; set; } 18 | 19 | public string Username { get; set; } 20 | 21 | public DateTime Created { get; set; } 22 | 23 | public string CreatedBy { get; set; } 24 | 25 | public DateTime Updated { get; set; } 26 | 27 | public string UpdatedBy { get; set; } 28 | 29 | public Byte[] RowVersion { get; set; } 30 | 31 | #endregion 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Parsing/ParsedEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace EntityFrameworkCore.Generator.Metadata.Parsing 6 | { 7 | [DebuggerDisplay("Table: {TableName}, Entity: {EntityClass}, Mapping: {MappingClass}")] 8 | public class ParsedEntity 9 | { 10 | public ParsedEntity() 11 | { 12 | Properties = new List(); 13 | Relationships = new List(); 14 | } 15 | 16 | public string EntityClass { get; set; } 17 | public string MappingClass { get; set; } 18 | 19 | public string TableName { get; set; } 20 | public string TableSchema { get; set; } 21 | 22 | public List Properties { get; private set; } 23 | public List Relationships { get; private set; } 24 | } 25 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Database/Tracker.PostgreSQL.Database.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | PreserveNewest 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Tenant/Validation/TenantCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | namespace Tracker.Core.Domain.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TenantCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TenantCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(100); 21 | RuleFor(p => p.Description).MaximumLength(255); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Tenant/Validation/TenantUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | namespace Tracker.Core.Domain.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TenantUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TenantUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(100); 21 | RuleFor(p => p.Description).MaximumLength(255); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Parsing/ParsedRelationship.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace EntityFrameworkCore.Generator.Metadata.Parsing 6 | { 7 | [DebuggerDisplay("This: {ThisPropertyName}, Other: {OtherPropertyName}")] 8 | public class ParsedRelationship 9 | { 10 | public ParsedRelationship() 11 | { 12 | ThisProperties = new List(); 13 | } 14 | 15 | public string ThisPropertyName { get; set; } 16 | public List ThisProperties { get; private set; } 17 | 18 | public string OtherPropertyName { get; set; } 19 | 20 | public bool IsValid() 21 | { 22 | return !string.IsNullOrEmpty(ThisPropertyName) 23 | && !string.IsNullOrEmpty(OtherPropertyName) 24 | && ThisProperties.Count > 0; 25 | } 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Web/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:26364", 8 | "sslPort": 44377 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "Tracker.Web": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "swagger", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator/OptionsCommandBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using McMaster.Extensions.CommandLineUtils; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace EntityFrameworkCore.Generator 6 | { 7 | public abstract class OptionsCommandBase : CommandBase 8 | { 9 | protected OptionsCommandBase(ILoggerFactory logger, IConsole console, IGeneratorOptionsSerializer serializer) 10 | : base(logger, console) 11 | { 12 | Serializer = serializer; 13 | } 14 | 15 | protected IGeneratorOptionsSerializer Serializer { get; } 16 | 17 | [Option("-d ", Description = "The root working directory")] 18 | public string WorkingDirectory { get; set; } = Environment.CurrentDirectory; 19 | 20 | [Option("-f ", Description = "The options file name")] 21 | public string OptionsFile { get; set; } = GeneratorOptionsSerializer.OptionsFileName; 22 | } 23 | } -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Entity Framework Core Generator 2 | theme: readthedocs 3 | repo_url: https://github.com/loresoft/EntityFrameworkCore.Generator 4 | 5 | pages: 6 | - Home: index.md 7 | 8 | - Quick Start: quickStart.md 9 | - Database Connection: connectionString.md 10 | - Database Providers: providers.md 11 | - Regeneration: regeneration.md 12 | - Generation Configuration: configuration.md 13 | - Configuration Variables: variables.md 14 | - Command Line Reference: commands.md 15 | 16 | - EntityFramework Templates: 17 | - Data Context: ef/dataContext.md 18 | - Entity: ef/entity.md 19 | - Mapping: ef/mapping.md 20 | - Extensions: ef/extensions.md 21 | 22 | - Model Templates: 23 | - Shared Configuration: md/shared.md 24 | - Read Model: md/read.md 25 | - Create Model: md/create.md 26 | - Update Model: md/update.md 27 | - Validation: md/validation.md 28 | - Object Mapper: md/mapper.md 29 | 30 | - Script Templates: scripts.md 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Models/IdentityUserRoleReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TrackerSchema.Core.Domain.Identity.Models 5 | { 6 | /// 7 | /// View Model class 8 | /// 9 | public partial class IdentityUserRoleReadModel 10 | { 11 | #region Generated Properties 12 | /// 13 | /// Gets or sets the property value for 'UserId'. 14 | /// 15 | /// 16 | /// The property value for 'UserId'. 17 | /// 18 | public Guid UserId { get; set; } 19 | 20 | /// 21 | /// Gets or sets the property value for 'RoleId'. 22 | /// 23 | /// 24 | /// The property value for 'RoleId'. 25 | /// 26 | public Guid RoleId { get; set; } 27 | 28 | #endregion 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/RoleProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class RoleProfile 9 | : AutoMapper.Profile 10 | { 11 | public RoleProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/TaskProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class TaskProfile 9 | : AutoMapper.Profile 10 | { 11 | public TaskProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/UserProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class UserProfile 9 | : AutoMapper.Profile 10 | { 11 | public UserProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Audit/Validation/AuditCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class AuditCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public AuditCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Content).NotEmpty(); 21 | RuleFor(p => p.Username).NotEmpty(); 22 | RuleFor(p => p.Username).MaximumLength(50); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Audit/Validation/AuditUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class AuditUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public AuditUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Content).NotEmpty(); 21 | RuleFor(p => p.Username).NotEmpty(); 22 | RuleFor(p => p.Username).MaximumLength(50); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Models/IdentityUserRoleCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TrackerSchema.Core.Domain.Identity.Models 5 | { 6 | /// 7 | /// View Model class 8 | /// 9 | public partial class IdentityUserRoleCreateModel 10 | { 11 | #region Generated Properties 12 | /// 13 | /// Gets or sets the property value for 'UserId'. 14 | /// 15 | /// 16 | /// The property value for 'UserId'. 17 | /// 18 | public Guid UserId { get; set; } 19 | 20 | /// 21 | /// Gets or sets the property value for 'RoleId'. 22 | /// 23 | /// 24 | /// The property value for 'RoleId'. 25 | /// 26 | public Guid RoleId { get; set; } 27 | 28 | #endregion 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Models/IdentityUserRoleUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TrackerSchema.Core.Domain.Identity.Models 5 | { 6 | /// 7 | /// View Model class 8 | /// 9 | public partial class IdentityUserRoleUpdateModel 10 | { 11 | #region Generated Properties 12 | /// 13 | /// Gets or sets the property value for 'UserId'. 14 | /// 15 | /// 16 | /// The property value for 'UserId'. 17 | /// 18 | public Guid UserId { get; set; } 19 | 20 | /// 21 | /// Gets or sets the property value for 'RoleId'. 22 | /// 23 | /// 24 | /// The property value for 'RoleId'. 25 | /// 26 | public Guid RoleId { get; set; } 27 | 28 | #endregion 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/AuditProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class AuditProfile 9 | : AutoMapper.Profile 10 | { 11 | public AuditProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/TaskExtended/Validation/TaskExtendedCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class TaskExtendedCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TaskExtendedCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Browser).MaximumLength(256); 21 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/TaskExtended/Validation/TaskExtendedUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class TaskExtendedUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TaskExtendedUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Browser).MaximumLength(256); 21 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 22 | #endregion 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Status/Validation/StatusCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class StatusCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public StatusCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Name).NotEmpty(); 21 | RuleFor(p => p.Name).MaximumLength(100); 22 | RuleFor(p => p.Description).MaximumLength(255); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Status/Validation/StatusUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class StatusUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public StatusUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Name).NotEmpty(); 21 | RuleFor(p => p.Name).MaximumLength(100); 22 | RuleFor(p => p.Description).MaximumLength(255); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/StatusProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class StatusProfile 9 | : AutoMapper.Profile 10 | { 11 | public StatusProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Priority/Validation/PriorityCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class PriorityCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public PriorityCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Name).NotEmpty(); 21 | RuleFor(p => p.Name).MaximumLength(100); 22 | RuleFor(p => p.Description).MaximumLength(255); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Priority/Validation/PriorityUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class PriorityUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public PriorityUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.Name).NotEmpty(); 21 | RuleFor(p => p.Name).MaximumLength(100); 22 | RuleFor(p => p.Description).MaximumLength(255); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Role/Models/RoleReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class RoleReadModel 11 | : EntityReadModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserRole/Models/UserRoleReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class UserRoleReadModel 11 | : EntityReadModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'UserId'. 16 | /// 17 | /// 18 | /// The property value for 'UserId'. 19 | /// 20 | public Guid UserId { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'RoleId'. 24 | /// 25 | /// 26 | /// The property value for 'RoleId'. 27 | /// 28 | public Guid RoleId { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/ModelScriptTemplate.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Metadata.Generation; 2 | using EntityFrameworkCore.Generator.Options; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace EntityFrameworkCore.Generator.Scripts 6 | { 7 | public class ModelScriptTemplate : ScriptTemplateBase 8 | { 9 | private Model _model; 10 | 11 | public ModelScriptTemplate(ILoggerFactory loggerFactory, GeneratorOptions generatorOptions, TemplateOptions templateOptions) 12 | : base(loggerFactory, generatorOptions, templateOptions) 13 | { 14 | } 15 | 16 | public void RunScript(Model model) 17 | { 18 | _model = model; 19 | 20 | WriteCode(); 21 | } 22 | 23 | protected override ModelScriptVariables CreateVariables() 24 | { 25 | return new ModelScriptVariables(_model, GeneratorOptions, TemplateOptions); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Role/Models/RoleCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class RoleCreateModel 11 | : EntityCreateModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Role/Models/RoleUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class RoleUpdateModel 11 | : EntityUpdateModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserRole/Models/UserRoleCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class UserRoleCreateModel 11 | : EntityCreateModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'UserId'. 16 | /// 17 | /// 18 | /// The property value for 'UserId'. 19 | /// 20 | public Guid UserId { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'RoleId'. 24 | /// 25 | /// 26 | /// The property value for 'RoleId'. 27 | /// 28 | public Guid RoleId { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/UserRole/Models/UserRoleUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class UserRoleUpdateModel 11 | : EntityUpdateModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'UserId'. 16 | /// 17 | /// 18 | /// The property value for 'UserId'. 19 | /// 20 | public Guid UserId { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'RoleId'. 24 | /// 25 | /// 26 | /// The property value for 'RoleId'. 27 | /// 28 | public Guid RoleId { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/PriorityProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class PriorityProfile 9 | : AutoMapper.Profile 10 | { 11 | public PriorityProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/UserRoleProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class UserRoleProfile 9 | : AutoMapper.Profile 10 | { 11 | public UserRoleProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/EntityScriptTemplate.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Metadata.Generation; 2 | using EntityFrameworkCore.Generator.Options; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace EntityFrameworkCore.Generator.Scripts 6 | { 7 | public class EntityScriptTemplate : ScriptTemplateBase 8 | { 9 | private Entity _entity; 10 | 11 | public EntityScriptTemplate(ILoggerFactory loggerFactory, GeneratorOptions generatorOptions, TemplateOptions templateOptions) 12 | : base(loggerFactory, generatorOptions, templateOptions) 13 | { 14 | } 15 | 16 | public void RunScript(Entity entity) 17 | { 18 | _entity = entity; 19 | 20 | WriteCode(); 21 | } 22 | 23 | protected override EntityScriptVariables CreateVariables() 24 | { 25 | return new EntityScriptVariables(_entity, GeneratorOptions, TemplateOptions); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/UserLoginProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class UserLoginProfile 9 | : AutoMapper.Profile 10 | { 11 | public UserLoginProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 3.1.0.{build} 2 | os: Visual Studio 2019 3 | 4 | environment: 5 | ASPNETCORE_ENVIRONMENT: appveyor 6 | COVERALLS_REPO_TOKEN: 7 | secure: FUpI+qx/M+lkfdUL40MekgpNGvOvPUy2TOJo0tEpUgUpHgwTDX0uYKUtQy8pcTyf 8 | 9 | init: 10 | - git config --global core.autocrlf input 11 | 12 | services: 13 | - mssql2017 14 | 15 | dotnet_csproj: 16 | patch: true 17 | file: 'build\version.props' 18 | version: '{version}' 19 | package_version: '{version}' 20 | assembly_version: '{version}' 21 | file_version: '{version}' 22 | informational_version: '{version}' 23 | 24 | build_script: 25 | - dotnet pack EntityFrameworkCore.Generator.sln --configuration Release --include-symbols --include-source 26 | 27 | test_script: 28 | - dotnet test EntityFrameworkCore.Generator.sln --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[xunit*]*" 29 | 30 | artifacts: 31 | - path: artifacts\*.*nupkg 32 | name: Packages 33 | 34 | deploy: 35 | - provider: Environment 36 | name: MyGet -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | .NET Core command-line (CLI) tool to generate Entity Framework Core source files. 4 | 5 | ## Install 6 | 7 | The Entity Framework Core Generator tool is available on nuget.org via package name `EntityFrameworkCore.Generator`. 8 | 9 | To install EntityFrameworkCore.Generator, run the following command in the console 10 | 11 | dotnet tool install --global EntityFrameworkCore.Generator 12 | 13 | More information about NuGet package available at 14 | 15 | 16 | ## Features 17 | 18 | - Entity Framework Core database first model generation 19 | - Safe regeneration via region replacement 20 | - Safe Renaming via mapping file parsing 21 | - Optionally generate read, create and update models from entity 22 | - Optionally generate validation and object mapper classes 23 | 24 | ## Usage 25 | 26 | To generate source code files from your database, use the generate command with your connection string. 27 | 28 | efg generate -c 29 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/User/Validation/UserCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class UserCreateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public UserCreateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.EmailAddress).NotEmpty(); 21 | RuleFor(p => p.EmailAddress).MaximumLength(256); 22 | RuleFor(p => p.DisplayName).NotEmpty(); 23 | RuleFor(p => p.DisplayName).MaximumLength(256); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/User/Validation/UserUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.Core.Domain.Models; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Tracker.Core.Domain.Validation 7 | { 8 | /// 9 | /// Validator class for . 10 | /// 11 | public partial class UserUpdateModelValidator 12 | : AbstractValidator 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public UserUpdateModelValidator() 18 | { 19 | #region Generated Constructor 20 | RuleFor(p => p.EmailAddress).NotEmpty(); 21 | RuleFor(p => p.EmailAddress).MaximumLength(256); 22 | RuleFor(p => p.DisplayName).NotEmpty(); 23 | RuleFor(p => p.DisplayName).MaximumLength(256); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Options; 2 | using FluentAssertions; 3 | using FluentCommand.SqlServer.Tests; 4 | using Microsoft.Extensions.Logging.Abstractions; 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | 8 | namespace EntityFrameworkCore.Generator.Core.Tests 9 | { 10 | public class CodeGeneratorTests : DatabaseTestBase 11 | { 12 | public CodeGeneratorTests(ITestOutputHelper output, DatabaseFixture databaseFixture) : base(output, databaseFixture) 13 | { 14 | } 15 | 16 | [Fact] 17 | public void Generate() 18 | { 19 | var generatorOptions = new GeneratorOptions(); 20 | generatorOptions.Database.ConnectionString = Database.ConnectionString; 21 | 22 | var generator = new CodeGenerator(NullLoggerFactory.Instance); 23 | var result = generator.Generate(generatorOptions); 24 | 25 | 26 | result.Should().BeTrue(); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Mapping/TaskExtendedProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.PostgreSQL.Core.Data.Entities; 4 | using Tracker.PostgreSQL.Core.Domain.Models; 5 | 6 | namespace Tracker.PostgreSQL.Core.Domain.Mapping 7 | { 8 | public partial class TaskExtendedProfile 9 | : AutoMapper.Profile 10 | { 11 | public TaskExtendedProfile() 12 | { 13 | CreateMap(); 14 | 15 | CreateMap(); 16 | 17 | CreateMap(); 18 | 19 | CreateMap(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Role/Mapping/RoleProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class RoleProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public RoleProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); 22 | 23 | CreateMap(); 24 | 25 | CreateMap() 26 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.FromBase64String(s.RowVersion))); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/User/Mapping/UserProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class UserProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public UserProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); 22 | 23 | CreateMap(); 24 | 25 | CreateMap() 26 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.FromBase64String(s.RowVersion))); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerTaskCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerTaskCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerTaskCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Title).NotEmpty(); 20 | RuleFor(p => p.Title).MaximumLength(255); 21 | RuleFor(p => p.CreatedBy).MaximumLength(100); 22 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerTaskUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerTaskUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerTaskUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Title).NotEmpty(); 20 | RuleFor(p => p.Title).MaximumLength(255); 21 | RuleFor(p => p.CreatedBy).MaximumLength(100); 22 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Scripts/ContextScriptTemplate.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.Generator.Metadata.Generation; 2 | using EntityFrameworkCore.Generator.Options; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace EntityFrameworkCore.Generator.Scripts 6 | { 7 | public class ContextScriptTemplate : ScriptTemplateBase 8 | { 9 | private EntityContext _entityContext; 10 | 11 | public ContextScriptTemplate(ILoggerFactory loggerFactory, GeneratorOptions generatorOptions, TemplateOptions templateOptions) 12 | : base(loggerFactory, generatorOptions, templateOptions) 13 | { 14 | } 15 | 16 | public void RunScript(EntityContext entityContext) 17 | { 18 | _entityContext = entityContext; 19 | 20 | WriteCode(); 21 | } 22 | 23 | protected override ContextScriptVariables CreateVariables() 24 | { 25 | return new ContextScriptVariables(_entityContext, GeneratorOptions, TemplateOptions); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityRoleCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityRoleCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityRoleCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(256); 21 | RuleFor(p => p.CreatedBy).MaximumLength(100); 22 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityRoleUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityRoleUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityRoleUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(256); 21 | RuleFor(p => p.CreatedBy).MaximumLength(100); 22 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Status/Mapping/StatusProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class StatusProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public StatusProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); 22 | 23 | CreateMap(); 24 | 25 | CreateMap() 26 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.FromBase64String(s.RowVersion))); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/Role.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class Role 7 | { 8 | public Role() 9 | { 10 | #region Generated Constructor 11 | UserRoles = new HashSet(); 12 | #endregion 13 | } 14 | 15 | #region Generated Properties 16 | public Guid Id { get; set; } 17 | 18 | public string Name { get; set; } 19 | 20 | public string Description { get; set; } 21 | 22 | public DateTime Created { get; set; } 23 | 24 | public string CreatedBy { get; set; } 25 | 26 | public DateTime Updated { get; set; } 27 | 28 | public string UpdatedBy { get; set; } 29 | 30 | public Byte[] RowVersion { get; set; } 31 | 32 | #endregion 33 | 34 | #region Generated Relationships 35 | public virtual ICollection UserRoles { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Tenant/Mapping/TenantProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | namespace Tracker.Core.Domain.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class TenantProfile 12 | : Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TenantProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/TaskExtended.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class TaskExtended 7 | { 8 | public TaskExtended() 9 | { 10 | #region Generated Constructor 11 | #endregion 12 | } 13 | 14 | #region Generated Properties 15 | public Guid TaskId { get; set; } 16 | 17 | public string UserAgent { get; set; } 18 | 19 | public string Browser { get; set; } 20 | 21 | public string OperatingSystem { get; set; } 22 | 23 | public DateTime Created { get; set; } 24 | 25 | public string CreatedBy { get; set; } 26 | 27 | public DateTime Updated { get; set; } 28 | 29 | public string UpdatedBy { get; set; } 30 | 31 | public Byte[] RowVersion { get; set; } 32 | 33 | #endregion 34 | 35 | #region Generated Relationships 36 | public virtual Task Task { get; set; } 37 | 38 | #endregion 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Priority/Mapping/PriorityProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class PriorityProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public PriorityProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); 22 | 23 | CreateMap(); 24 | 25 | CreateMap() 26 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.FromBase64String(s.RowVersion))); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/TaskReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class TaskReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public Guid StatusId { get; set; } 12 | 13 | public Guid? PriorityId { get; set; } 14 | 15 | public string Title { get; set; } 16 | 17 | public string Description { get; set; } 18 | 19 | public DateTime? StartDate { get; set; } 20 | 21 | public DateTime? DueDate { get; set; } 22 | 23 | public DateTime? CompleteDate { get; set; } 24 | 25 | public Guid? AssignedId { get; set; } 26 | 27 | public DateTime Created { get; set; } 28 | 29 | public string CreatedBy { get; set; } 30 | 31 | public DateTime Updated { get; set; } 32 | 33 | public string UpdatedBy { get; set; } 34 | 35 | public Byte[] RowVersion { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/Audit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class Audit 7 | { 8 | public Audit() 9 | { 10 | #region Generated Constructor 11 | #endregion 12 | } 13 | 14 | #region Generated Properties 15 | public Guid Id { get; set; } 16 | 17 | public DateTime Date { get; set; } 18 | 19 | public Guid? UserId { get; set; } 20 | 21 | public Guid? TaskId { get; set; } 22 | 23 | public string Content { get; set; } 24 | 25 | public string Username { get; set; } 26 | 27 | public DateTime Created { get; set; } 28 | 29 | public string CreatedBy { get; set; } 30 | 31 | public DateTime Updated { get; set; } 32 | 33 | public string UpdatedBy { get; set; } 34 | 35 | public Byte[] RowVersion { get; set; } 36 | 37 | #endregion 38 | 39 | #region Generated Relationships 40 | #endregion 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/TaskCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class TaskCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public Guid StatusId { get; set; } 12 | 13 | public Guid? PriorityId { get; set; } 14 | 15 | public string Title { get; set; } 16 | 17 | public string Description { get; set; } 18 | 19 | public DateTime? StartDate { get; set; } 20 | 21 | public DateTime? DueDate { get; set; } 22 | 23 | public DateTime? CompleteDate { get; set; } 24 | 25 | public Guid? AssignedId { get; set; } 26 | 27 | public DateTime Created { get; set; } 28 | 29 | public string CreatedBy { get; set; } 30 | 31 | public DateTime Updated { get; set; } 32 | 33 | public string UpdatedBy { get; set; } 34 | 35 | public Byte[] RowVersion { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/TaskUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class TaskUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public Guid StatusId { get; set; } 12 | 13 | public Guid? PriorityId { get; set; } 14 | 15 | public string Title { get; set; } 16 | 17 | public string Description { get; set; } 18 | 19 | public DateTime? StartDate { get; set; } 20 | 21 | public DateTime? DueDate { get; set; } 22 | 23 | public DateTime? CompleteDate { get; set; } 24 | 25 | public Guid? AssignedId { get; set; } 26 | 27 | public DateTime Created { get; set; } 28 | 29 | public string CreatedBy { get; set; } 30 | 31 | public DateTime Updated { get; set; } 32 | 33 | public string UpdatedBy { get; set; } 34 | 35 | public Byte[] RowVersion { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerAuditCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerAuditCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerAuditCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Content).NotEmpty(); 20 | RuleFor(p => p.Username).NotEmpty(); 21 | RuleFor(p => p.Username).MaximumLength(50); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerAuditUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerAuditUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerAuditUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Content).NotEmpty(); 20 | RuleFor(p => p.Username).NotEmpty(); 21 | RuleFor(p => p.Username).MaximumLength(50); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerTaskExtendedCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerTaskExtendedCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerTaskExtendedCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Browser).MaximumLength(256); 20 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 21 | RuleFor(p => p.CreatedBy).MaximumLength(100); 22 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerTaskExtendedUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerTaskExtendedUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerTaskExtendedUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Browser).MaximumLength(256); 20 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 21 | RuleFor(p => p.CreatedBy).MaximumLength(100); 22 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 23 | #endregion 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 LoreSoft 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerStatusCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerStatusCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerStatusCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(100); 21 | RuleFor(p => p.Description).MaximumLength(255); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerStatusUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerStatusUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerStatusUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(100); 21 | RuleFor(p => p.Description).MaximumLength(255); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/TaskExtended/Mapping/TaskExtendedProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class TaskExtendedProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public TaskExtendedProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))); 22 | 23 | CreateMap(); 24 | 25 | CreateMap() 26 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.FromBase64String(s.RowVersion))); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator/EntityFrameworkCore.Generator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Exe 6 | netcoreapp3.1 7 | efg 8 | true 9 | 10 | 11 | 12 | 1591,EF1001 13 | 14 | 15 | 16 | 1591,EF1001 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerPriorityCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerPriorityCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerPriorityCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(100); 21 | RuleFor(p => p.Description).MaximumLength(255); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Validation/TrackerPriorityUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Tracker.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Tracker.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class TrackerPriorityUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public TrackerPriorityUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.Name).NotEmpty(); 20 | RuleFor(p => p.Name).MaximumLength(100); 21 | RuleFor(p => p.Description).MaximumLength(255); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/Status.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class Status 7 | { 8 | public Status() 9 | { 10 | #region Generated Constructor 11 | Tasks = new HashSet(); 12 | #endregion 13 | } 14 | 15 | #region Generated Properties 16 | public Guid Id { get; set; } 17 | 18 | public string Name { get; set; } 19 | 20 | public string Description { get; set; } 21 | 22 | public int DisplayOrder { get; set; } 23 | 24 | public bool IsActive { get; set; } 25 | 26 | public DateTime Created { get; set; } 27 | 28 | public string CreatedBy { get; set; } 29 | 30 | public DateTime Updated { get; set; } 31 | 32 | public string UpdatedBy { get; set; } 33 | 34 | public Byte[] RowVersion { get; set; } 35 | 36 | #endregion 37 | 38 | #region Generated Relationships 39 | public virtual ICollection Tasks { get; set; } 40 | 41 | #endregion 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/Priority.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class Priority 7 | { 8 | public Priority() 9 | { 10 | #region Generated Constructor 11 | Tasks = new HashSet(); 12 | #endregion 13 | } 14 | 15 | #region Generated Properties 16 | public Guid Id { get; set; } 17 | 18 | public string Name { get; set; } 19 | 20 | public string Description { get; set; } 21 | 22 | public int DisplayOrder { get; set; } 23 | 24 | public bool IsActive { get; set; } 25 | 26 | public DateTime Created { get; set; } 27 | 28 | public string CreatedBy { get; set; } 29 | 30 | public DateTime Updated { get; set; } 31 | 32 | public string UpdatedBy { get; set; } 33 | 34 | public Byte[] RowVersion { get; set; } 35 | 36 | #endregion 37 | 38 | #region Generated Relationships 39 | public virtual ICollection Tasks { get; set; } 40 | 41 | #endregion 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Parsing/RegionParser.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using EntityFrameworkCore.Generator.Metadata.Parsing; 3 | using Microsoft.CodeAnalysis.CSharp; 4 | using Microsoft.CodeAnalysis.CSharp.Syntax; 5 | 6 | namespace EntityFrameworkCore.Generator.Parsing 7 | { 8 | public class RegionParser 9 | { 10 | public Dictionary ParseRegions(string code) 11 | { 12 | var syntaxTree = CSharpSyntaxTree.ParseText(code); 13 | var root = (CompilationUnitSyntax)syntaxTree.GetRoot(); 14 | 15 | var visitor = new RegionVisitor(); 16 | visitor.Visit(root); 17 | 18 | var regions = visitor.Regions; 19 | 20 | // extract content using start and end indexes 21 | foreach (var pair in regions) 22 | { 23 | var region = pair.Value; 24 | 25 | var start = region.StartIndex; 26 | var end = region.EndIndex; 27 | var length = end - start; 28 | 29 | region.Content = code.Substring(start, length); 30 | } 31 | 32 | return regions; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /docs/md/shared.md: -------------------------------------------------------------------------------- 1 | # Shared Model Template 2 | 3 | The [Read](read.md), [Create](create.md) and [Update](update.md) model templates share the following [configuration](../configuration.md). 4 | 5 | ## Configuration 6 | 7 | Shared configuration values are applied to all the model templates. 8 | 9 | Example configuration 10 | 11 | ```YAML 12 | model: 13 | shared: 14 | exclude: 15 | entities: 16 | - 'EmailDelivery' 17 | - 'UserLogin' 18 | properties: 19 | - 'User\.PasswordHash$' 20 | - 'User\.ResetHash$' 21 | ``` 22 | 23 | ### namespace 24 | 25 | The namespace for the model class. *Variables Supported* 26 | 27 | ### directory 28 | 29 | The directory location to write the source file. *Variables Supported* 30 | 31 | ### exclude 32 | 33 | The exclude configuration is a list regular expressions for entities and properties to exclude in the model. 34 | 35 | #### entities 36 | 37 | Exclude all entities that match any of the listed regular expressions. 38 | 39 | #### properties 40 | 41 | Exclude all properties that match any of the listed regular expressions. The value to match contains the parent entity the property belongs too, `Entity.Property`. 42 | 43 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityUserCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityUserCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityUserCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.EmailAddress).NotEmpty(); 20 | RuleFor(p => p.EmailAddress).MaximumLength(256); 21 | RuleFor(p => p.DisplayName).NotEmpty(); 22 | RuleFor(p => p.DisplayName).MaximumLength(256); 23 | RuleFor(p => p.CreatedBy).MaximumLength(100); 24 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 25 | #endregion 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityUserUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityUserUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityUserUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.EmailAddress).NotEmpty(); 20 | RuleFor(p => p.EmailAddress).MaximumLength(256); 21 | RuleFor(p => p.DisplayName).NotEmpty(); 22 | RuleFor(p => p.DisplayName).MaximumLength(256); 23 | RuleFor(p => p.CreatedBy).MaximumLength(100); 24 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 25 | #endregion 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Tenant/Models/TenantReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.Core.Domain.Models 5 | { 6 | /// 7 | /// View Model class 8 | /// 9 | public partial class TenantReadModel 10 | : EntityReadModel 11 | { 12 | #region Generated Properties 13 | /// 14 | /// Gets or sets the property value for 'Name'. 15 | /// 16 | /// 17 | /// The property value for 'Name'. 18 | /// 19 | public string Name { get; set; } 20 | 21 | /// 22 | /// Gets or sets the property value for 'Description'. 23 | /// 24 | /// 25 | /// The property value for 'Description'. 26 | /// 27 | public string Description { get; set; } 28 | 29 | /// 30 | /// Gets or sets the property value for 'IsActive'. 31 | /// 32 | /// 33 | /// The property value for 'IsActive'. 34 | /// 35 | public bool IsActive { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Tenant/Models/TenantCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.Core.Domain.Models 5 | { 6 | /// 7 | /// View Model class 8 | /// 9 | public partial class TenantCreateModel 10 | : EntityCreateModel 11 | { 12 | #region Generated Properties 13 | /// 14 | /// Gets or sets the property value for 'Name'. 15 | /// 16 | /// 17 | /// The property value for 'Name'. 18 | /// 19 | public string Name { get; set; } 20 | 21 | /// 22 | /// Gets or sets the property value for 'Description'. 23 | /// 24 | /// 25 | /// The property value for 'Description'. 26 | /// 27 | public string Description { get; set; } 28 | 29 | /// 30 | /// Gets or sets the property value for 'IsActive'. 31 | /// 32 | /// 33 | /// The property value for 'IsActive'. 34 | /// 35 | public bool IsActive { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Tenant/Models/TenantUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.Core.Domain.Models 5 | { 6 | /// 7 | /// View Model class 8 | /// 9 | public partial class TenantUpdateModel 10 | : EntityUpdateModel 11 | { 12 | #region Generated Properties 13 | /// 14 | /// Gets or sets the property value for 'Name'. 15 | /// 16 | /// 17 | /// The property value for 'Name'. 18 | /// 19 | public string Name { get; set; } 20 | 21 | /// 22 | /// Gets or sets the property value for 'Description'. 23 | /// 24 | /// 25 | /// The property value for 'Description'. 26 | /// 27 | public string Description { get; set; } 28 | 29 | /// 30 | /// Gets or sets the property value for 'IsActive'. 31 | /// 32 | /// 33 | /// The property value for 'IsActive'. 34 | /// 35 | public bool IsActive { get; set; } 36 | 37 | #endregion 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/UserLoginCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class UserLoginCreateModelValidator 8 | : AbstractValidator 9 | { 10 | public UserLoginCreateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.EmailAddress).NotEmpty(); 14 | RuleFor(p => p.EmailAddress).MaximumLength(256); 15 | RuleFor(p => p.Browser).MaximumLength(256); 16 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 17 | RuleFor(p => p.DeviceFamily).MaximumLength(256); 18 | RuleFor(p => p.DeviceBrand).MaximumLength(256); 19 | RuleFor(p => p.DeviceModel).MaximumLength(256); 20 | RuleFor(p => p.IpAddress).MaximumLength(50); 21 | RuleFor(p => p.FailureMessage).MaximumLength(256); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Validation/UserLoginUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using Tracker.PostgreSQL.Core.Domain.Models; 4 | 5 | namespace Tracker.PostgreSQL.Core.Domain.Validation 6 | { 7 | public partial class UserLoginUpdateModelValidator 8 | : AbstractValidator 9 | { 10 | public UserLoginUpdateModelValidator() 11 | { 12 | #region Generated Constructor 13 | RuleFor(p => p.EmailAddress).NotEmpty(); 14 | RuleFor(p => p.EmailAddress).MaximumLength(256); 15 | RuleFor(p => p.Browser).MaximumLength(256); 16 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 17 | RuleFor(p => p.DeviceFamily).MaximumLength(256); 18 | RuleFor(p => p.DeviceBrand).MaximumLength(256); 19 | RuleFor(p => p.DeviceModel).MaximumLength(256); 20 | RuleFor(p => p.IpAddress).MaximumLength(50); 21 | RuleFor(p => p.FailureMessage).MaximumLength(256); 22 | RuleFor(p => p.CreatedBy).MaximumLength(100); 23 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 24 | #endregion 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Model.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkCore.Generator.Metadata.Generation 4 | { 5 | public class Model : ModelBase, IOptionVariable 6 | { 7 | public Model() 8 | { 9 | Properties = new PropertyCollection(); 10 | } 11 | 12 | public Entity Entity { get; set; } 13 | 14 | public ModelType ModelType { get; set; } 15 | 16 | public string ModelNamespace { get; set; } 17 | 18 | public string ModelClass { get; set; } 19 | 20 | public string ModelBaseClass { get; set; } 21 | 22 | 23 | public string ValidatorNamespace { get; set; } 24 | 25 | public string ValidatorClass { get; set; } 26 | 27 | public string ValidatorBaseClass { get; set; } 28 | 29 | 30 | public PropertyCollection Properties { get; set; } 31 | 32 | 33 | void IOptionVariable.Set(VariableDictionary variableDictionary) 34 | { 35 | variableDictionary.Set(VariableConstants.ModelName, ModelClass); 36 | } 37 | 38 | void IOptionVariable.Remove(VariableDictionary variableDictionary) 39 | { 40 | variableDictionary.Remove(VariableConstants.ModelName); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/SelectionOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace EntityFrameworkCore.Generator.Options 5 | { 6 | /// 7 | /// Selection options 8 | /// 9 | public class SelectionOptions 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public SelectionOptions() 15 | { 16 | Entities = new List(); 17 | Properties = new List(); 18 | } 19 | 20 | /// 21 | /// Gets or sets a list of regular expression of entities to select. 22 | /// 23 | /// 24 | /// The list of regular expression of entities to select. 25 | /// 26 | public List Entities { get; set; } 27 | 28 | /// 29 | /// Gets or sets a list of regular expression of properties to select. 30 | /// 31 | /// 32 | /// The list of regular expression of properties to select. 33 | /// 34 | public List Properties { get; set; } 35 | } 36 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserLoginReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserLoginReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string EmailAddress { get; set; } 12 | 13 | public Guid? UserId { get; set; } 14 | 15 | public string UserAgent { get; set; } 16 | 17 | public string Browser { get; set; } 18 | 19 | public string OperatingSystem { get; set; } 20 | 21 | public string DeviceFamily { get; set; } 22 | 23 | public string DeviceBrand { get; set; } 24 | 25 | public string DeviceModel { get; set; } 26 | 27 | public string IpAddress { get; set; } 28 | 29 | public bool IsSuccessful { get; set; } 30 | 31 | public string FailureMessage { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserLoginCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserLoginCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string EmailAddress { get; set; } 12 | 13 | public Guid? UserId { get; set; } 14 | 15 | public string UserAgent { get; set; } 16 | 17 | public string Browser { get; set; } 18 | 19 | public string OperatingSystem { get; set; } 20 | 21 | public string DeviceFamily { get; set; } 22 | 23 | public string DeviceBrand { get; set; } 24 | 25 | public string DeviceModel { get; set; } 26 | 27 | public string IpAddress { get; set; } 28 | 29 | public bool IsSuccessful { get; set; } 30 | 31 | public string FailureMessage { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserLoginUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserLoginUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string EmailAddress { get; set; } 12 | 13 | public Guid? UserId { get; set; } 14 | 15 | public string UserAgent { get; set; } 16 | 17 | public string Browser { get; set; } 18 | 19 | public string OperatingSystem { get; set; } 20 | 21 | public string DeviceFamily { get; set; } 22 | 23 | public string DeviceBrand { get; set; } 24 | 25 | public string DeviceModel { get; set; } 26 | 27 | public string IpAddress { get; set; } 28 | 29 | public bool IsSuccessful { get; set; } 30 | 31 | public string FailureMessage { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserReadModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string EmailAddress { get; set; } 12 | 13 | public bool IsEmailAddressConfirmed { get; set; } 14 | 15 | public string DisplayName { get; set; } 16 | 17 | public string PasswordHash { get; set; } 18 | 19 | public string ResetHash { get; set; } 20 | 21 | public string InviteHash { get; set; } 22 | 23 | public int AccessFailedCount { get; set; } 24 | 25 | public bool LockoutEnabled { get; set; } 26 | 27 | public DateTime? LockoutEnd { get; set; } 28 | 29 | public DateTime? LastLogin { get; set; } 30 | 31 | public bool IsDeleted { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserCreateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string EmailAddress { get; set; } 12 | 13 | public bool IsEmailAddressConfirmed { get; set; } 14 | 15 | public string DisplayName { get; set; } 16 | 17 | public string PasswordHash { get; set; } 18 | 19 | public string ResetHash { get; set; } 20 | 21 | public string InviteHash { get; set; } 22 | 23 | public int AccessFailedCount { get; set; } 24 | 25 | public bool LockoutEnabled { get; set; } 26 | 27 | public DateTime? LockoutEnd { get; set; } 28 | 29 | public DateTime? LastLogin { get; set; } 30 | 31 | public bool IsDeleted { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Domain/Models/UserUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Domain.Models 5 | { 6 | public partial class UserUpdateModel 7 | { 8 | #region Generated Properties 9 | public Guid Id { get; set; } 10 | 11 | public string EmailAddress { get; set; } 12 | 13 | public bool IsEmailAddressConfirmed { get; set; } 14 | 15 | public string DisplayName { get; set; } 16 | 17 | public string PasswordHash { get; set; } 18 | 19 | public string ResetHash { get; set; } 20 | 21 | public string InviteHash { get; set; } 22 | 23 | public int AccessFailedCount { get; set; } 24 | 25 | public bool LockoutEnabled { get; set; } 26 | 27 | public DateTime? LockoutEnd { get; set; } 28 | 29 | public DateTime? LastLogin { get; set; } 30 | 31 | public bool IsDeleted { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/ScriptOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace EntityFrameworkCore.Generator.Options 4 | { 5 | public class ScriptOptions : OptionsBase 6 | { 7 | public ScriptOptions(VariableDictionary variables, string prefix) 8 | : base(variables, AppendPrefix(prefix, "Script")) 9 | { 10 | Context = new List(); 11 | Entity = new List(); 12 | Model = new List(); 13 | } 14 | 15 | /// 16 | /// Gets or sets the list context script templates. 17 | /// 18 | /// The list context script templates. 19 | public List Context { get; set; } 20 | 21 | /// 22 | /// Gets or sets the list entity script templates. 23 | /// 24 | /// The list entity script templates. 25 | public List Entity { get; set; } 26 | 27 | /// 28 | /// Gets or sets the list model script templates. 29 | /// 30 | /// The list model script templates. 31 | public List Model { get; set; } 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Mapping/TrackerTaskProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Tracker.Entities; 4 | using TrackerSchema.Core.Domain.Tracker.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Tracker.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class TrackerTaskProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TrackerTaskProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Mapping/TrackerAuditProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Tracker.Entities; 4 | using TrackerSchema.Core.Domain.Tracker.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Tracker.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class TrackerAuditProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TrackerAuditProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Task/Mapping/TaskProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using Tracker.Core.Data.Entities; 4 | using Tracker.Core.Domain.Models; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Tracker.Core.Domain.Mapping 8 | { 9 | /// 10 | /// Mapper class for entity . 11 | /// 12 | public partial class TaskProfile 13 | : Profile 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public TaskProfile() 19 | { 20 | CreateMap() 21 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.ToBase64String(s.RowVersion))) 22 | .ForMember(d => d.PriorityName, opt => opt.MapFrom(s => s.Priority.Name)) 23 | .ForMember(d => d.StatusName, opt => opt.MapFrom(s => s.Status.Name)) 24 | .ForMember(d => d.AssignedEmail, opt => opt.MapFrom(s => s.AssignedUser.EmailAddress)); 25 | 26 | CreateMap(); 27 | 28 | CreateMap() 29 | .ForMember(d => d.RowVersion, opt => opt.MapFrom(s => Convert.FromBase64String(s.RowVersion))); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Queries/AuditExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace Tracker.PostgreSQL.Core.Data.Queries 8 | { 9 | public static partial class AuditExtensions 10 | { 11 | #region Generated Extensions 12 | public static Tracker.PostgreSQL.Core.Data.Entities.Audit GetByKey(this IQueryable queryable, Guid id) 13 | { 14 | if (queryable is DbSet dbSet) 15 | return dbSet.Find(id); 16 | 17 | return queryable.FirstOrDefault(q => q.Id == id); 18 | } 19 | 20 | public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) 21 | { 22 | if (queryable is DbSet dbSet) 23 | return dbSet.FindAsync(id); 24 | 25 | var task = queryable.FirstOrDefaultAsync(q => q.Id == id); 26 | return new ValueTask(task); 27 | } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Mapping/IdentityRoleProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Identity.Entities; 4 | using TrackerSchema.Core.Domain.Identity.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Identity.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class IdentityRoleProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public IdentityRoleProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Mapping/IdentityUserProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Identity.Entities; 4 | using TrackerSchema.Core.Domain.Identity.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Identity.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class IdentityUserProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public IdentityUserProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Mapping/TrackerStatusProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Tracker.Entities; 4 | using TrackerSchema.Core.Domain.Tracker.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Tracker.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class TrackerStatusProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TrackerStatusProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Queries/StatusExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace Tracker.PostgreSQL.Core.Data.Queries 8 | { 9 | public static partial class StatusExtensions 10 | { 11 | #region Generated Extensions 12 | public static Tracker.PostgreSQL.Core.Data.Entities.Status GetByKey(this IQueryable queryable, Guid id) 13 | { 14 | if (queryable is DbSet dbSet) 15 | return dbSet.Find(id); 16 | 17 | return queryable.FirstOrDefault(q => q.Id == id); 18 | } 19 | 20 | public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) 21 | { 22 | if (queryable is DbSet dbSet) 23 | return dbSet.FindAsync(id); 24 | 25 | var task = queryable.FirstOrDefaultAsync(q => q.Id == id); 26 | return new ValueTask(task); 27 | } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Options/ProjectOptions.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFrameworkCore.Generator.Options 2 | { 3 | /// 4 | /// Project options 5 | /// 6 | public class ProjectOptions : OptionsBase 7 | { 8 | 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | public ProjectOptions(VariableDictionary variables, string prefix) 13 | : base(variables, AppendPrefix(prefix, "Project")) 14 | { 15 | Namespace = "{Database.Name}"; 16 | Directory = @".\"; 17 | } 18 | 19 | /// 20 | /// Gets or sets the project root namespace. 21 | /// 22 | /// 23 | /// The project root namespace. 24 | /// 25 | public string Namespace 26 | { 27 | get => GetProperty(); 28 | set => SetProperty(value); 29 | } 30 | 31 | /// 32 | /// Gets or sets the project directory. 33 | /// 34 | /// 35 | /// The project directory. 36 | /// 37 | public string Directory 38 | { 39 | get => GetProperty(); 40 | set => SetProperty(value); 41 | } 42 | 43 | } 44 | } -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Queries/PriorityExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace Tracker.PostgreSQL.Core.Data.Queries 8 | { 9 | public static partial class PriorityExtensions 10 | { 11 | #region Generated Extensions 12 | public static Tracker.PostgreSQL.Core.Data.Entities.Priority GetByKey(this IQueryable queryable, Guid id) 13 | { 14 | if (queryable is DbSet dbSet) 15 | return dbSet.Find(id); 16 | 17 | return queryable.FirstOrDefault(q => q.Id == id); 18 | } 19 | 20 | public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid id) 21 | { 22 | if (queryable is DbSet dbSet) 23 | return dbSet.FindAsync(id); 24 | 25 | var task = queryable.FirstOrDefaultAsync(q => q.Id == id); 26 | return new ValueTask(task); 27 | } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Mapping/TrackerPriorityProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Tracker.Entities; 4 | using TrackerSchema.Core.Domain.Tracker.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Tracker.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class TrackerPriorityProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TrackerPriorityProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Mapping/IdentityUserRoleProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Identity.Entities; 4 | using TrackerSchema.Core.Domain.Identity.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Identity.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class IdentityUserRoleProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public IdentityUserRoleProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/EntityFrameworkCore.Generator.Core/Metadata/Generation/Relationship.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace EntityFrameworkCore.Generator.Metadata.Generation 4 | { 5 | [DebuggerDisplay("Primary: {PrimaryEntity}, Property: {PropertyName}, Relationship: {RelationshipName}")] 6 | public class Relationship : ModelBase 7 | { 8 | public Relationship() 9 | { 10 | Properties = new PropertyCollection(); 11 | PrimaryProperties = new PropertyCollection(); 12 | } 13 | 14 | public string RelationshipName { get; set; } 15 | 16 | 17 | public Entity Entity { get; set; } 18 | 19 | public PropertyCollection Properties { get; set; } 20 | 21 | public string PropertyName { get; set; } 22 | 23 | public Cardinality Cardinality { get; set; } 24 | 25 | 26 | public Entity PrimaryEntity { get; set; } 27 | 28 | public PropertyCollection PrimaryProperties { get; set; } 29 | 30 | public string PrimaryPropertyName { get; set; } 31 | 32 | public Cardinality PrimaryCardinality { get; set; } 33 | 34 | 35 | public bool? CascadeDelete { get; set; } 36 | public bool IsForeignKey { get; set; } 37 | public bool IsMapped { get; set; } 38 | 39 | public bool IsOneToOne => Cardinality != Cardinality.Many && PrimaryCardinality != Cardinality.Many; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Mapping/IdentityUserLoginProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Identity.Entities; 4 | using TrackerSchema.Core.Domain.Identity.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Identity.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class IdentityUserLoginProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public IdentityUserLoginProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Tracker/Mapping/TrackerTaskExtendedProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoMapper; 3 | using TrackerSchema.Core.Data.Tracker.Entities; 4 | using TrackerSchema.Core.Domain.Tracker.Models; 5 | 6 | namespace TrackerSchema.Core.Domain.Tracker.Mapping 7 | { 8 | /// 9 | /// Mapper class for entity . 10 | /// 11 | public partial class TrackerTaskExtendedProfile 12 | : AutoMapper.Profile 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public TrackerTaskExtendedProfile() 18 | { 19 | CreateMap(); 20 | 21 | CreateMap(); 22 | 23 | CreateMap(); 24 | 25 | CreateMap(); 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Database/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using DbUp; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace TrackerSchema.Database 7 | { 8 | class Program 9 | { 10 | static int Main(string[] args) 11 | { 12 | var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"; 13 | var builder = new ConfigurationBuilder() 14 | .AddJsonFile("appsettings.json") 15 | .AddJsonFile($"appsettings.{environmentName}.json", true) 16 | .AddEnvironmentVariables(); 17 | 18 | var configuration = builder.Build(); 19 | 20 | var connectionString = configuration.GetConnectionString("TrackerSchema"); 21 | 22 | EnsureDatabase.For 23 | .SqlDatabase(connectionString); 24 | 25 | var upgradeEngine = DeployChanges.To 26 | .SqlDatabase(connectionString) 27 | .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) 28 | .LogToConsole() 29 | .Build(); 30 | 31 | var result = upgradeEngine.PerformUpgrade(); 32 | 33 | if (result.Successful) 34 | return 0; 35 | 36 | Console.Error.WriteLine($"Exception: '{result.Error}'"); 37 | 38 | return 1; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Queries/TaskExtendedExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace Tracker.PostgreSQL.Core.Data.Queries 8 | { 9 | public static partial class TaskExtendedExtensions 10 | { 11 | #region Generated Extensions 12 | public static Tracker.PostgreSQL.Core.Data.Entities.TaskExtended GetByKey(this IQueryable queryable, Guid taskId) 13 | { 14 | if (queryable is DbSet dbSet) 15 | return dbSet.Find(taskId); 16 | 17 | return queryable.FirstOrDefault(q => q.TaskId == taskId); 18 | } 19 | 20 | public static ValueTask GetByKeyAsync(this IQueryable queryable, Guid taskId) 21 | { 22 | if (queryable is DbSet dbSet) 23 | return dbSet.FindAsync(taskId); 24 | 25 | var task = queryable.FirstOrDefaultAsync(q => q.TaskId == taskId); 26 | return new ValueTask(task); 27 | } 28 | 29 | #endregion 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Database/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using DbUp; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace Tracker.PostgreSQL.Database 7 | { 8 | class Program 9 | { 10 | static int Main(string[] args) 11 | { 12 | var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"; 13 | var builder = new ConfigurationBuilder() 14 | .AddJsonFile("appsettings.json") 15 | .AddJsonFile($"appsettings.{environmentName}.json", true) 16 | .AddEnvironmentVariables(); 17 | 18 | var configuration = builder.Build(); 19 | 20 | var connectionString = configuration.GetConnectionString("Tracker"); 21 | 22 | EnsureDatabase.For 23 | .PostgresqlDatabase(connectionString); 24 | 25 | var upgradeEngine = DeployChanges.To 26 | .PostgresqlDatabase(connectionString) 27 | .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) 28 | .LogToConsole() 29 | .Build(); 30 | 31 | var result = upgradeEngine.PerformUpgrade(); 32 | 33 | if (result.Successful) 34 | return 0; 35 | 36 | Console.Error.WriteLine($"Exception: '{result.Error}'"); 37 | 38 | return 1; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/UserLogin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class UserLogin 7 | { 8 | public UserLogin() 9 | { 10 | #region Generated Constructor 11 | #endregion 12 | } 13 | 14 | #region Generated Properties 15 | public Guid Id { get; set; } 16 | 17 | public string EmailAddress { get; set; } 18 | 19 | public Guid? UserId { get; set; } 20 | 21 | public string UserAgent { get; set; } 22 | 23 | public string Browser { get; set; } 24 | 25 | public string OperatingSystem { get; set; } 26 | 27 | public string DeviceFamily { get; set; } 28 | 29 | public string DeviceBrand { get; set; } 30 | 31 | public string DeviceModel { get; set; } 32 | 33 | public string IpAddress { get; set; } 34 | 35 | public bool IsSuccessful { get; set; } 36 | 37 | public string FailureMessage { get; set; } 38 | 39 | public DateTime Created { get; set; } 40 | 41 | public string CreatedBy { get; set; } 42 | 43 | public DateTime Updated { get; set; } 44 | 45 | public string UpdatedBy { get; set; } 46 | 47 | public Byte[] RowVersion { get; set; } 48 | 49 | #endregion 50 | 51 | #region Generated Relationships 52 | public virtual User User { get; set; } 53 | 54 | #endregion 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Status/Models/StatusReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class StatusReadModel 11 | : EntityReadModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | /// 31 | /// Gets or sets the property value for 'DisplayOrder'. 32 | /// 33 | /// 34 | /// The property value for 'DisplayOrder'. 35 | /// 36 | public int DisplayOrder { get; set; } 37 | 38 | /// 39 | /// Gets or sets the property value for 'IsActive'. 40 | /// 41 | /// 42 | /// The property value for 'IsActive'. 43 | /// 44 | public bool IsActive { get; set; } 45 | 46 | #endregion 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/Tracker.PostgreSQL/Tracker.PostgreSQL.Core/Data/Entities/Task.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Tracker.PostgreSQL.Core.Data.Entities 5 | { 6 | public partial class Task 7 | { 8 | public Task() 9 | { 10 | #region Generated Constructor 11 | #endregion 12 | } 13 | 14 | #region Generated Properties 15 | public Guid Id { get; set; } 16 | 17 | public Guid StatusId { get; set; } 18 | 19 | public Guid? PriorityId { get; set; } 20 | 21 | public string Title { get; set; } 22 | 23 | public string Description { get; set; } 24 | 25 | public DateTime? StartDate { get; set; } 26 | 27 | public DateTime? DueDate { get; set; } 28 | 29 | public DateTime? CompleteDate { get; set; } 30 | 31 | public Guid? AssignedId { get; set; } 32 | 33 | public DateTime Created { get; set; } 34 | 35 | public string CreatedBy { get; set; } 36 | 37 | public DateTime Updated { get; set; } 38 | 39 | public string UpdatedBy { get; set; } 40 | 41 | public Byte[] RowVersion { get; set; } 42 | 43 | #endregion 44 | 45 | #region Generated Relationships 46 | public virtual User AssignedUser { get; set; } 47 | 48 | public virtual Priority Priority { get; set; } 49 | 50 | public virtual Status Status { get; set; } 51 | 52 | public virtual TaskExtended TaskExtended { get; set; } 53 | 54 | #endregion 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Priority/Models/PriorityReadModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class PriorityReadModel 11 | : EntityReadModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | /// 31 | /// Gets or sets the property value for 'DisplayOrder'. 32 | /// 33 | /// 34 | /// The property value for 'DisplayOrder'. 35 | /// 36 | public int DisplayOrder { get; set; } 37 | 38 | /// 39 | /// Gets or sets the property value for 'IsActive'. 40 | /// 41 | /// 42 | /// The property value for 'IsActive'. 43 | /// 44 | public bool IsActive { get; set; } 45 | 46 | #endregion 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Status/Models/StatusCreateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class StatusCreateModel 11 | : EntityCreateModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | /// 31 | /// Gets or sets the property value for 'DisplayOrder'. 32 | /// 33 | /// 34 | /// The property value for 'DisplayOrder'. 35 | /// 36 | public int DisplayOrder { get; set; } 37 | 38 | /// 39 | /// Gets or sets the property value for 'IsActive'. 40 | /// 41 | /// 42 | /// The property value for 'IsActive'. 43 | /// 44 | public bool IsActive { get; set; } 45 | 46 | #endregion 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/Tracker/Tracker.Core/Domain/Status/Models/StatusUpdateModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Tracker.Core.Domain.Models 6 | { 7 | /// 8 | /// View Model class 9 | /// 10 | public partial class StatusUpdateModel 11 | : EntityUpdateModel 12 | { 13 | #region Generated Properties 14 | /// 15 | /// Gets or sets the property value for 'Name'. 16 | /// 17 | /// 18 | /// The property value for 'Name'. 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the property value for 'Description'. 24 | /// 25 | /// 26 | /// The property value for 'Description'. 27 | /// 28 | public string Description { get; set; } 29 | 30 | /// 31 | /// Gets or sets the property value for 'DisplayOrder'. 32 | /// 33 | /// 34 | /// The property value for 'DisplayOrder'. 35 | /// 36 | public int DisplayOrder { get; set; } 37 | 38 | /// 39 | /// Gets or sets the property value for 'IsActive'. 40 | /// 41 | /// 42 | /// The property value for 'IsActive'. 43 | /// 44 | public bool IsActive { get; set; } 45 | 46 | #endregion 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityUserLoginCreateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityUserLoginCreateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityUserLoginCreateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.EmailAddress).NotEmpty(); 20 | RuleFor(p => p.EmailAddress).MaximumLength(256); 21 | RuleFor(p => p.Browser).MaximumLength(256); 22 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 23 | RuleFor(p => p.DeviceFamily).MaximumLength(256); 24 | RuleFor(p => p.DeviceBrand).MaximumLength(256); 25 | RuleFor(p => p.DeviceModel).MaximumLength(256); 26 | RuleFor(p => p.IpAddress).MaximumLength(50); 27 | RuleFor(p => p.FailureMessage).MaximumLength(256); 28 | RuleFor(p => p.CreatedBy).MaximumLength(100); 29 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 30 | #endregion 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sample/TrackerSchema/TrackerSchema.Core/Domain/Identity/Validation/IdentityUserLoginUpdateModelValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | using TrackerSchema.Core.Domain.Identity.Models; 4 | 5 | namespace TrackerSchema.Core.Domain.Identity.Validation 6 | { 7 | /// 8 | /// Validator class for . 9 | /// 10 | public partial class IdentityUserLoginUpdateModelValidator 11 | : AbstractValidator 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public IdentityUserLoginUpdateModelValidator() 17 | { 18 | #region Generated Constructor 19 | RuleFor(p => p.EmailAddress).NotEmpty(); 20 | RuleFor(p => p.EmailAddress).MaximumLength(256); 21 | RuleFor(p => p.Browser).MaximumLength(256); 22 | RuleFor(p => p.OperatingSystem).MaximumLength(256); 23 | RuleFor(p => p.DeviceFamily).MaximumLength(256); 24 | RuleFor(p => p.DeviceBrand).MaximumLength(256); 25 | RuleFor(p => p.DeviceModel).MaximumLength(256); 26 | RuleFor(p => p.IpAddress).MaximumLength(50); 27 | RuleFor(p => p.FailureMessage).MaximumLength(256); 28 | RuleFor(p => p.CreatedBy).MaximumLength(100); 29 | RuleFor(p => p.UpdatedBy).MaximumLength(100); 30 | #endregion 31 | } 32 | 33 | } 34 | } 35 | --------------------------------------------------------------------------------