Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

namespace {{namespace}}
{
{{#if class-annotation}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
{{#if comment}}
/// <summary>
/// {{comment}}
/// </summary>
{{/if}}
{{#if class-annotation}}
{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
{{{> constructor}}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{#each properties}}
{{#if property-comment}}
{{spaces 8}}/// <summary>
{{spaces 8}}/// {{property-comment}}
{{spaces 8}}/// </summary>
{{/if}}
{{#each property-annotations}}
{{spaces 8}}{{{property-annotation}}}
{{/each}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{{> imports}}

{{#if comment}}
/**
* {{comment}}
*/
{{/if}}
export interface {{class}} {
{{{> properties}}}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{#each properties}}
{{#if property-comment}}
{{spaces 4}}/**
{{spaces 4}}* {{property-comment}}
{{spaces 4}}*/
{{/if}}
{{spaces 4}}{{property-name}}: {{property-type}};
{{/each}}
{{#if nav-properties}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ protected override void GenerateClass(IEntityType entityType)
}

var transformedEntityName = EntityTypeTransformationService.TransformEntityName(entityType.Name);


TemplateData.Add("comment", entityType.GetComment());
TemplateData.Add("class", transformedEntityName);

GenerateConstructor(entityType);
Expand Down Expand Up @@ -220,6 +221,7 @@ protected override void GenerateProperties(IEntityType entityType)
{ "property-type", propertyType },
{ "property-name", property.Name },
{ "property-annotations", PropertyAnnotationsData },
{ "property-comment", property.GetComment() },
{ "property-isnullable", property.IsNullable },
{ "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public List<Dictionary<string, object>> TransformProperties(List<Dictionary<stri
{ "property-type", transformedProp.PropertyType },
{ "property-name", transformedProp.PropertyName },
{ "property-annotations", property["property-annotations"] },
{ "property-comment", property["property-comment"] },
{ "property-isnullable", transformedProp.PropertyIsNullable },
{ "nullable-reference-types", property["nullable-reference-types"] }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ protected override void GenerateClass(IEntityType entityType)

var transformedEntityName = EntityTypeTransformationService.TransformEntityName(entityType.Name);

TemplateData.Add("comment", entityType.GetComment());
TemplateData.Add("class", transformedEntityName);

GenerateConstructor(entityType);
Expand Down Expand Up @@ -178,6 +179,7 @@ protected override void GenerateProperties(IEntityType entityType)
{ "property-type", TypeScriptHelper.TypeName(property.ClrType) },
{ "property-name", TypeScriptHelper.ToCamelCase(property.Name) },
{ "property-annotations", new List<Dictionary<string, object>>() },
{ "property-comment", property.GetComment() },
{ "property-isnullable", property.IsNullable },
{ "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

namespace {{namespace}}
{
{{#if class-annotation}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
{{#if comment}}
/// <summary>
/// {{comment}}
/// </summary>
{{/if}}
{{#if class-annotation}}
{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
{{{> constructor}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public NorthwindDbContext(DbContextOptions options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>()
.HasComment("A category of products")
.Property(category => category.CategoryName)
.HasComment("The name of a category");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ public partial class {{class}} : DbContext
namespace {{namespace}}
{
{{#if class-annotation}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
{{#if comment}}
/// <summary>
/// {{comment}}
/// </summary>
{{/if}}
{{#if class-annotation}}
{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
{{{> constructor}}}
Expand Down
24 changes: 22 additions & 2 deletions test/Scaffolding.Handlebars.Tests/ExpectedContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>(entity =>
{
entity.HasComment(""A category of products"");
entity.Property(e => e.CategoryName)
.IsRequired()
.HasMaxLength(15);
.HasMaxLength(15)
.HasComment(""The name of a category"");
});
modelBuilder.Entity<Product>(entity =>
Expand Down Expand Up @@ -94,6 +97,13 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>(entity =>
{
entity.HasComment(""A category of products"");
entity.Property(e => e.CategoryName).HasComment(""The name of a category"");
});
modelBuilder.Entity<Product>(entity =>
{
entity.HasIndex(e => e.CategoryId);
Expand Down Expand Up @@ -143,9 +153,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
entity.ToTable(""Category"");
entity.HasComment(""A category of products"");
entity.Property(e => e.CategoryName)
.IsRequired()
.HasMaxLength(15);
.HasMaxLength(15)
.HasComment(""The name of a category"");
});
modelBuilder.Entity<Product>(entity =>
Expand Down Expand Up @@ -205,6 +218,13 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>(entity =>
{
entity.HasComment(""A category of products"");
entity.Property(e => e.CategoryName).HasComment(""The name of a category"");
});
modelBuilder.Entity<Product>(entity =>
{
entity.HasIndex(e => e.CategoryId);
Expand Down
24 changes: 24 additions & 0 deletions test/Scaffolding.Handlebars.Tests/ExpectedEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ private static class ExpectedEntities
namespace FakeNamespace
{
/// <summary>
/// A category of products
/// </summary>
public partial class Category
{
public Category()
Expand All @@ -18,6 +21,9 @@ public Category()
}
public int CategoryId { get; set; }
/// <summary>
/// The name of a category
/// </summary>
public string CategoryName { get; set; }
public virtual ICollection<Product> Product { get; set; }
Expand Down Expand Up @@ -56,6 +62,9 @@ private static class ExpectedEntitiesWithAnnotations
namespace FakeNamespace
{
/// <summary>
/// A category of products
/// </summary>
public partial class Category
{
public Category()
Expand All @@ -65,6 +74,9 @@ public Category()
[Key]
public int CategoryId { get; set; }
/// <summary>
/// The name of a category
/// </summary>
[Required]
[StringLength(15)]
public string CategoryName { get; set; }
Expand Down Expand Up @@ -112,6 +124,9 @@ private static class ExpectedEntitiesPluralized
namespace FakeNamespace
{
/// <summary>
/// A category of products
/// </summary>
public partial class Category
{
public Category()
Expand All @@ -120,6 +135,9 @@ public Category()
}
public int CategoryId { get; set; }
/// <summary>
/// The name of a category
/// </summary>
public string CategoryName { get; set; }
public virtual ICollection<Product> Products { get; set; }
Expand Down Expand Up @@ -158,6 +176,9 @@ private static class ExpectedEntitiesWithAnnotationsPluralized
namespace FakeNamespace
{
/// <summary>
/// A category of products
/// </summary>
[Table(""Category"")]
public partial class Category
{
Expand All @@ -168,6 +189,9 @@ public Category()
[Key]
public int CategoryId { get; set; }
/// <summary>
/// The name of a category
/// </summary>
[Required]
[StringLength(15)]
public string CategoryName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>(entity =>
{
entity.HasComment(""A category of products"");
entity.Property(e => e.CategoryName)
.IsRequired()
.HasMaxLength(15);
.HasMaxLength(15)
.HasComment(""The name of a category"");
});
modelBuilder.Entity<Product>(entity =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ private static class ExpectedEntities
public const string CategoryClass =
@"import { Product } from './Product';

/**
* A category of products
*/
export interface Category {
categoryId: number;
/**
* The name of a category
*/
categoryName: string;
product: Product[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ public partial class {{class}} : DbContext
namespace {{namespace}}
{
{{#if class-annotation}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
{{#if comment}}
/// <summary>
/// {{comment}}
/// </summary>
{{/if}}
{{#if class-annotation}}
{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
{{{> constructor}}}
Expand Down