Skip to content

Commit

Permalink
add mapping attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Jul 9, 2024
1 parent 89e0b4e commit acd2ddc
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ data:
relationshipNaming: Preserve|Plural|Suffix
#include XML documentation
document: false

#include mapping attributes on the entity classes
mappingAttributes: true
# Generate class names with prefixed schema name eg. dbo.MyTable = DboMyTable
prefixWithSchemaName: false

Expand Down
4 changes: 4 additions & 0 deletions docs/ef/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ Control if class names should be generated with schema name prefixed eg. dbo.MyT

Include XML documentation for the generated class. Default: `false`

### mappingAttributes

Include mapping attributes on the entity classes. Default: `false`

### renaming

Rename entities and properties with regular expressions
Expand Down
15 changes: 15 additions & 0 deletions sample/Tracker/Tracker.Core/Data/Entities/Audit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Tracker.Core.Data.Entities;
/// <summary>
/// Entity class representing data for table 'Audit'.
/// </summary>
[System.ComponentModel.DataAnnotations.Schema.Table("Audit", Schema = "dbo")]
public partial class Audit : IHaveIdentifier
{
/// <summary>
Expand All @@ -25,6 +26,8 @@ public Audit()
/// <value>
/// The property value representing column 'Id'.
/// </value>
[System.ComponentModel.DataAnnotations.Key()]
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
public Guid Id { get; set; }

/// <summary>
Expand All @@ -33,6 +36,7 @@ public Audit()
/// <value>
/// The property value representing column 'Date'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Date", TypeName = "datetime")]
public DateTime Date { get; set; }

/// <summary>
Expand All @@ -41,6 +45,7 @@ public Audit()
/// <value>
/// The property value representing column 'UserId'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("UserId", TypeName = "uniqueidentifier")]
public Guid? UserId { get; set; }

/// <summary>
Expand All @@ -49,6 +54,7 @@ public Audit()
/// <value>
/// The property value representing column 'TaskId'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("TaskId", TypeName = "uniqueidentifier")]
public Guid? TaskId { get; set; }

/// <summary>
Expand All @@ -57,6 +63,7 @@ public Audit()
/// <value>
/// The property value representing column 'Content'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Content", TypeName = "nvarchar(max)")]
public string Content { get; set; } = null!;

/// <summary>
Expand All @@ -65,6 +72,7 @@ public Audit()
/// <value>
/// The property value representing column 'Username'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Username", TypeName = "nvarchar(50)")]
public string Username { get; set; } = null!;

/// <summary>
Expand All @@ -73,6 +81,7 @@ public Audit()
/// <value>
/// The property value representing column 'Created'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Created", TypeName = "datetimeoffset")]
public DateTimeOffset Created { get; set; }

/// <summary>
Expand All @@ -81,6 +90,7 @@ public Audit()
/// <value>
/// The property value representing column 'CreatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("CreatedBy", TypeName = "nvarchar(100)")]
public string? CreatedBy { get; set; }

/// <summary>
Expand All @@ -89,6 +99,7 @@ public Audit()
/// <value>
/// The property value representing column 'Updated'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Updated", TypeName = "datetimeoffset")]
public DateTimeOffset Updated { get; set; }

/// <summary>
Expand All @@ -97,6 +108,7 @@ public Audit()
/// <value>
/// The property value representing column 'UpdatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("UpdatedBy", TypeName = "nvarchar(100)")]
public string? UpdatedBy { get; set; }

/// <summary>
Expand All @@ -105,6 +117,9 @@ public Audit()
/// <value>
/// The property value representing column 'RowVersion'.
/// </value>
[System.ComponentModel.DataAnnotations.ConcurrencyCheck()]
[System.ComponentModel.DataAnnotations.Schema.Column("RowVersion", TypeName = "rowversion")]
[System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)]
public Byte[] RowVersion { get; set; } = null!;

#endregion
Expand Down
14 changes: 14 additions & 0 deletions sample/Tracker/Tracker.Core/Data/Entities/Priority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Tracker.Core.Data.Entities;
/// <summary>
/// Entity class representing data for table 'Priority'.
/// </summary>
[System.ComponentModel.DataAnnotations.Schema.Table("Priority", Schema = "dbo")]
public partial class Priority : IHaveIdentifier, ITrackCreated, ITrackUpdated
{
/// <summary>
Expand All @@ -27,6 +28,8 @@ public Priority()
/// <value>
/// The property value representing column 'Id'.
/// </value>
[System.ComponentModel.DataAnnotations.Key()]
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
public Guid Id { get; set; }

/// <summary>
Expand All @@ -35,6 +38,7 @@ public Priority()
/// <value>
/// The property value representing column 'Name'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Name", TypeName = "nvarchar(100)")]
public string Name { get; set; } = null!;

/// <summary>
Expand All @@ -43,6 +47,7 @@ public Priority()
/// <value>
/// The property value representing column 'Description'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Description", TypeName = "nvarchar(255)")]
public string? Description { get; set; }

/// <summary>
Expand All @@ -51,6 +56,7 @@ public Priority()
/// <value>
/// The property value representing column 'DisplayOrder'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("DisplayOrder", TypeName = "int")]
public int DisplayOrder { get; set; }

/// <summary>
Expand All @@ -59,6 +65,7 @@ public Priority()
/// <value>
/// The property value representing column 'IsActive'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("IsActive", TypeName = "bit")]
public bool IsActive { get; set; }

/// <summary>
Expand All @@ -67,6 +74,7 @@ public Priority()
/// <value>
/// The property value representing column 'Created'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Created", TypeName = "datetimeoffset")]
public DateTimeOffset Created { get; set; }

/// <summary>
Expand All @@ -75,6 +83,7 @@ public Priority()
/// <value>
/// The property value representing column 'CreatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("CreatedBy", TypeName = "nvarchar(100)")]
public string? CreatedBy { get; set; }

/// <summary>
Expand All @@ -83,6 +92,7 @@ public Priority()
/// <value>
/// The property value representing column 'Updated'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Updated", TypeName = "datetimeoffset")]
public DateTimeOffset Updated { get; set; }

/// <summary>
Expand All @@ -91,6 +101,7 @@ public Priority()
/// <value>
/// The property value representing column 'UpdatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("UpdatedBy", TypeName = "nvarchar(100)")]
public string? UpdatedBy { get; set; }

/// <summary>
Expand All @@ -99,6 +110,9 @@ public Priority()
/// <value>
/// The property value representing column 'RowVersion'.
/// </value>
[System.ComponentModel.DataAnnotations.ConcurrencyCheck()]
[System.ComponentModel.DataAnnotations.Schema.Column("RowVersion", TypeName = "rowversion")]
[System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)]
public Byte[] RowVersion { get; set; } = null!;

#endregion
Expand Down
12 changes: 12 additions & 0 deletions sample/Tracker/Tracker.Core/Data/Entities/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Tracker.Core.Data.Entities;
/// <summary>
/// Entity class representing data for table 'Role'.
/// </summary>
[System.ComponentModel.DataAnnotations.Schema.Table("Role", Schema = "dbo")]
public partial class Role : IHaveIdentifier, ITrackCreated, ITrackUpdated
{
/// <summary>
Expand All @@ -26,6 +27,8 @@ public Role()
/// <value>
/// The property value representing column 'Id'.
/// </value>
[System.ComponentModel.DataAnnotations.Key()]
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
public Guid Id { get; set; }

/// <summary>
Expand All @@ -34,6 +37,7 @@ public Role()
/// <value>
/// The property value representing column 'Name'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Name", TypeName = "nvarchar(256)")]
public string Name { get; set; } = null!;

/// <summary>
Expand All @@ -42,6 +46,7 @@ public Role()
/// <value>
/// The property value representing column 'Description'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Description", TypeName = "nvarchar(max)")]
public string? Description { get; set; }

/// <summary>
Expand All @@ -50,6 +55,7 @@ public Role()
/// <value>
/// The property value representing column 'Created'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Created", TypeName = "datetimeoffset")]
public DateTimeOffset Created { get; set; }

/// <summary>
Expand All @@ -58,6 +64,7 @@ public Role()
/// <value>
/// The property value representing column 'CreatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("CreatedBy", TypeName = "nvarchar(100)")]
public string? CreatedBy { get; set; }

/// <summary>
Expand All @@ -66,6 +73,7 @@ public Role()
/// <value>
/// The property value representing column 'Updated'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Updated", TypeName = "datetimeoffset")]
public DateTimeOffset Updated { get; set; }

/// <summary>
Expand All @@ -74,6 +82,7 @@ public Role()
/// <value>
/// The property value representing column 'UpdatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("UpdatedBy", TypeName = "nvarchar(100)")]
public string? UpdatedBy { get; set; }

/// <summary>
Expand All @@ -82,6 +91,9 @@ public Role()
/// <value>
/// The property value representing column 'RowVersion'.
/// </value>
[System.ComponentModel.DataAnnotations.ConcurrencyCheck()]
[System.ComponentModel.DataAnnotations.Schema.Column("RowVersion", TypeName = "rowversion")]
[System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)]
public Byte[] RowVersion { get; set; } = null!;

#endregion
Expand Down
14 changes: 14 additions & 0 deletions sample/Tracker/Tracker.Core/Data/Entities/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Tracker.Core.Data.Entities;
/// <summary>
/// Entity class representing data for table 'Status'.
/// </summary>
[System.ComponentModel.DataAnnotations.Schema.Table("Status", Schema = "dbo")]
public partial class Status : IHaveIdentifier, ITrackCreated, ITrackUpdated
{
/// <summary>
Expand All @@ -26,6 +27,8 @@ public Status()
/// <value>
/// The property value representing column 'Id'.
/// </value>
[System.ComponentModel.DataAnnotations.Key()]
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
public Guid Id { get; set; }

/// <summary>
Expand All @@ -34,6 +37,7 @@ public Status()
/// <value>
/// The property value representing column 'Name'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Name", TypeName = "nvarchar(100)")]
public string Name { get; set; } = null!;

/// <summary>
Expand All @@ -42,6 +46,7 @@ public Status()
/// <value>
/// The property value representing column 'Description'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Description", TypeName = "nvarchar(255)")]
public string? Description { get; set; }

/// <summary>
Expand All @@ -50,6 +55,7 @@ public Status()
/// <value>
/// The property value representing column 'DisplayOrder'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("DisplayOrder", TypeName = "int")]
public int DisplayOrder { get; set; }

/// <summary>
Expand All @@ -58,6 +64,7 @@ public Status()
/// <value>
/// The property value representing column 'IsActive'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("IsActive", TypeName = "bit")]
public bool IsActive { get; set; }

/// <summary>
Expand All @@ -66,6 +73,7 @@ public Status()
/// <value>
/// The property value representing column 'Created'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Created", TypeName = "datetimeoffset")]
public DateTimeOffset Created { get; set; }

/// <summary>
Expand All @@ -74,6 +82,7 @@ public Status()
/// <value>
/// The property value representing column 'CreatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("CreatedBy", TypeName = "nvarchar(100)")]
public string? CreatedBy { get; set; }

/// <summary>
Expand All @@ -82,6 +91,7 @@ public Status()
/// <value>
/// The property value representing column 'Updated'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("Updated", TypeName = "datetimeoffset")]
public DateTimeOffset Updated { get; set; }

/// <summary>
Expand All @@ -90,6 +100,7 @@ public Status()
/// <value>
/// The property value representing column 'UpdatedBy'.
/// </value>
[System.ComponentModel.DataAnnotations.Schema.Column("UpdatedBy", TypeName = "nvarchar(100)")]
public string? UpdatedBy { get; set; }

/// <summary>
Expand All @@ -98,6 +109,9 @@ public Status()
/// <value>
/// The property value representing column 'RowVersion'.
/// </value>
[System.ComponentModel.DataAnnotations.ConcurrencyCheck()]
[System.ComponentModel.DataAnnotations.Schema.Column("RowVersion", TypeName = "rowversion")]
[System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)]
public Byte[] RowVersion { get; set; } = null!;

#endregion
Expand Down
Loading

0 comments on commit acd2ddc

Please sign in to comment.