Skip to content

Commit acd2ddc

Browse files
committed
add mapping attribute support
1 parent 89e0b4e commit acd2ddc

File tree

20 files changed

+213
-12
lines changed

20 files changed

+213
-12
lines changed

docs/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ data:
8282
relationshipNaming: Preserve|Plural|Suffix
8383
#include XML documentation
8484
document: false
85-
85+
#include mapping attributes on the entity classes
86+
mappingAttributes: true
8687
# Generate class names with prefixed schema name eg. dbo.MyTable = DboMyTable
8788
prefixWithSchemaName: false
8889

docs/ef/entity.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Control if class names should be generated with schema name prefixed eg. dbo.MyT
103103

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

106+
### mappingAttributes
107+
108+
Include mapping attributes on the entity classes. Default: `false`
109+
106110
### renaming
107111

108112
Rename entities and properties with regular expressions

sample/Tracker/Tracker.Core/Data/Entities/Audit.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Tracker.Core.Data.Entities;
77
/// <summary>
88
/// Entity class representing data for table 'Audit'.
99
/// </summary>
10+
[System.ComponentModel.DataAnnotations.Schema.Table("Audit", Schema = "dbo")]
1011
public partial class Audit : IHaveIdentifier
1112
{
1213
/// <summary>
@@ -25,6 +26,8 @@ public Audit()
2526
/// <value>
2627
/// The property value representing column 'Id'.
2728
/// </value>
29+
[System.ComponentModel.DataAnnotations.Key()]
30+
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
2831
public Guid Id { get; set; }
2932

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

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

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

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

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

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

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

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

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

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

110125
#endregion

sample/Tracker/Tracker.Core/Data/Entities/Priority.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Tracker.Core.Data.Entities;
88
/// <summary>
99
/// Entity class representing data for table 'Priority'.
1010
/// </summary>
11+
[System.ComponentModel.DataAnnotations.Schema.Table("Priority", Schema = "dbo")]
1112
public partial class Priority : IHaveIdentifier, ITrackCreated, ITrackUpdated
1213
{
1314
/// <summary>
@@ -27,6 +28,8 @@ public Priority()
2728
/// <value>
2829
/// The property value representing column 'Id'.
2930
/// </value>
31+
[System.ComponentModel.DataAnnotations.Key()]
32+
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
3033
public Guid Id { get; set; }
3134

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

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

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

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

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

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

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

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

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

104118
#endregion

sample/Tracker/Tracker.Core/Data/Entities/Role.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Tracker.Core.Data.Entities;
77
/// <summary>
88
/// Entity class representing data for table 'Role'.
99
/// </summary>
10+
[System.ComponentModel.DataAnnotations.Schema.Table("Role", Schema = "dbo")]
1011
public partial class Role : IHaveIdentifier, ITrackCreated, ITrackUpdated
1112
{
1213
/// <summary>
@@ -26,6 +27,8 @@ public Role()
2627
/// <value>
2728
/// The property value representing column 'Id'.
2829
/// </value>
30+
[System.ComponentModel.DataAnnotations.Key()]
31+
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
2932
public Guid Id { get; set; }
3033

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

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

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

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

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

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

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

8799
#endregion

sample/Tracker/Tracker.Core/Data/Entities/Status.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Tracker.Core.Data.Entities;
77
/// <summary>
88
/// Entity class representing data for table 'Status'.
99
/// </summary>
10+
[System.ComponentModel.DataAnnotations.Schema.Table("Status", Schema = "dbo")]
1011
public partial class Status : IHaveIdentifier, ITrackCreated, ITrackUpdated
1112
{
1213
/// <summary>
@@ -26,6 +27,8 @@ public Status()
2627
/// <value>
2728
/// The property value representing column 'Id'.
2829
/// </value>
30+
[System.ComponentModel.DataAnnotations.Key()]
31+
[System.ComponentModel.DataAnnotations.Schema.Column("Id", TypeName = "uniqueidentifier")]
2932
public Guid Id { get; set; }
3033

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

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

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

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

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

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

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

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

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

103117
#endregion

0 commit comments

Comments
 (0)