Skip to content

Commit

Permalink
#832 Add more data annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
sjh37 committed Feb 13, 2024
1 parent 6a849e0 commit dca9911
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4001,6 +4001,7 @@
NameHumanCaseWithSuffix = table.NameHumanCaseWithSuffix(),
Schema = table.Schema.DbName,
PrimaryKeyNameHumanCase = primaryKey ?? table.PrimaryKeyNameHumanCase(),
NotUsingDataAnnotations = !Settings.UseDataAnnotations,
HasSchema = !string.IsNullOrEmpty(table.Schema.DbName),
ClassModifier = Settings.ConfigurationClassesModifiers,
ClassComment = table.WriteComments(),
Expand Down Expand Up @@ -17297,6 +17298,9 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
foreach (var attribute in Attributes.Distinct())
sb.AppendLine(attribute);

if (Settings.UseDataAnnotations)
sb.AppendLine($"[Table(\"{DbName}\", Schema = \"{Schema.DbName}\")]");

return sb.ToString();
}

Expand Down Expand Up @@ -17492,6 +17496,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
public string Schema { get; set; }
public string PrimaryKeyNameHumanCase { get; set; }
public bool HasSchema { get; set; }
public bool NotUsingDataAnnotations { get; set; }
public string ClassModifier { get; set; }
public string ClassComment { get; set; }
public List<string> Columns { get; set; }
Expand Down Expand Up @@ -20451,10 +20456,12 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}}

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down Expand Up @@ -22096,10 +22103,12 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}}

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down Expand Up @@ -23748,10 +23757,12 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}}

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down Expand Up @@ -25400,10 +25411,12 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}}

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down
1 change: 1 addition & 0 deletions Generator/Generators/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ public CodeOutput GeneratePocoConfiguration(Table table)
NameHumanCaseWithSuffix = table.NameHumanCaseWithSuffix(),
Schema = table.Schema.DbName,
PrimaryKeyNameHumanCase = primaryKey ?? table.PrimaryKeyNameHumanCase(),
NotUsingDataAnnotations = !Settings.UseDataAnnotations,
HasSchema = !string.IsNullOrEmpty(table.Schema.DbName),
ClassModifier = Settings.ConfigurationClassesModifiers,
ClassComment = table.WriteComments(),
Expand Down
2 changes: 1 addition & 1 deletion Generator/Generators/GeneratorEf6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override void SetupConfig(Column c)
sb.AppendFormat(".HasColumnName(@\"{0}\")", c.DbName);

var excludedHasColumnType = string.Empty;
if (!string.IsNullOrEmpty(c.SqlPropertyType))
if (!Settings.UseDataAnnotations && !string.IsNullOrEmpty(c.SqlPropertyType))
{
if(Column.ExcludedHasColumnType.Contains(c.SqlPropertyType))
excludedHasColumnType = string.Format(" // .HasColumnType(\"{0}\") was excluded", c.SqlPropertyType);
Expand Down
3 changes: 3 additions & 0 deletions Generator/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public string WriteClassAttributes()
foreach (var attribute in Attributes.Distinct())
sb.AppendLine(attribute);

if (Settings.UseDataAnnotations)
sb.AppendLine($"[Table(\"{DbName}\", Schema = \"{Schema.DbName}\")]");

return sb.ToString();
}

Expand Down
1 change: 1 addition & 0 deletions Generator/TemplateModels/PocoConfigurationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PocoConfigurationModel
public string Schema { get; set; }
public string PrimaryKeyNameHumanCase { get; set; }
public bool HasSchema { get; set; }
public bool NotUsingDataAnnotations { get; set; }
public string ClassModifier { get; set; }
public string ClassComment { get; set; }
public List<string> Columns { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions Generator/Templates/TemplateEfCore3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,10 +1485,12 @@ public override string PocoConfiguration()
public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}
Expand Down
2 changes: 2 additions & 0 deletions Generator/Templates/TemplateEfCore6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,10 +1538,12 @@ public override string PocoConfiguration()
public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}
Expand Down
2 changes: 2 additions & 0 deletions Generator/Templates/TemplateEfCore7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,12 @@ public override string PocoConfiguration()
public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}
Expand Down
2 changes: 2 additions & 0 deletions Generator/Templates/TemplateEfCore8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,12 @@ public override string PocoConfiguration()
public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}(""{{Name}}"", ""{{Schema}}"");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}(""{{Name}}"");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}("{{Name}}", "{{Schema}}");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}("{{Name}}");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}("{{Name}}", "{{Schema}}");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}("{{Name}}");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}("{{Name}}", "{{Schema}}");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}("{{Name}}");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

public void Configure(EntityTypeBuilder<{{NameHumanCaseWithSuffix}}> builder){{#newline}}
{{{#newline}}
{{#if NotUsingDataAnnotations}}
{{#if HasSchema}}
builder.{{ToTableOrView}}("{{Name}}", "{{Schema}}");{{#newline}}
{{#else}}
builder.{{ToTableOrView}}("{{Name}}");{{#newline}}
{{/if}}
{{/if}}
{{PrimaryKeyNameHumanCase}}{{#newline}}{{#newline}}

Expand Down

0 comments on commit dca9911

Please sign in to comment.