Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 35a129e

Browse files
authored
Update EF Extensions (#58)
1 parent 8bf3f22 commit 35a129e

4 files changed

Lines changed: 73 additions & 33 deletions

File tree

src/EntityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore/Extensions/EntityTypeBuilderExtensions.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,31 +136,46 @@ public static EntityTypeBuilder<TEntity> HasPropertyComment<TEntity, TProperty>(
136136

137137
return entityTypeBuilder;
138138
}
139-
139+
140140
/// <summary>
141-
/// Adds comments to the entity type and all its properties using documentation from XDoc.
142-
/// This method automatically maps XML comments from the entity class documentation to the database objects.
141+
/// Configures XML documentation for the entity type being configured.
143142
/// </summary>
144143
/// <typeparam name="TEntity">The entity type being configured</typeparam>
145144
/// <param name="builder">The builder for the entity type</param>
146145
/// <param name="xdoc">The XDoc instance used to extract documentation</param>
147146
/// <returns>The same entity type builder instance so that multiple calls can be chained</returns>
148-
public static EntityTypeBuilder<TEntity> MapXmlComments<TEntity>(
147+
public static EntityTypeBuilder<TEntity> ConfigureEntityXmlDocumentation<TEntity>(
149148
this EntityTypeBuilder<TEntity> builder,
150149
XDoc xdoc)
151150
where TEntity : class
152151
{
153152
var entityType = builder.Metadata;
154-
155-
entityType.ConfigureEntityTypeComment(xdoc);
156-
153+
entityType.ConfigureEntityXmlDocumentation(xdoc);
154+
155+
return builder;
156+
}
157+
158+
/// <summary>
159+
/// Configures XML documentation for all properties of the entity type being configured.
160+
/// </summary>
161+
/// <typeparam name="TEntity">The entity type being configured</typeparam>
162+
/// <param name="builder">The builder for the entity type</param>
163+
/// <param name="xdoc">The XDoc instance used to extract documentation</param>
164+
/// <returns>The same entity type builder instance so that multiple calls can be chained</returns>
165+
public static EntityTypeBuilder<TEntity> ConfigurePropertiesXmlDocumentation<TEntity>(
166+
this EntityTypeBuilder<TEntity> builder,
167+
XDoc xdoc)
168+
where TEntity : class
169+
{
170+
var entityType = builder.Metadata;
171+
157172
var properties = entityType.GetProperties();
158-
173+
159174
foreach (var property in properties)
160175
{
161-
entityType.ConfigureEntityPropertyComment(xdoc, property);
176+
entityType.ConfigurePropertyXmlDocumentation(xdoc, property);
162177
}
163-
178+
164179
return builder;
165180
}
166181
}

src/EntityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore/Extensions/ModelBuilderExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public static ModelBuilder ConfigureComments(this ModelBuilder modelBuilder, XDo
2020

2121
foreach (var entityType in entityTypes)
2222
{
23-
entityType.ConfigureEntityComments(xDoc);
23+
entityType.ConfigureEntityXmlDocumentation(xDoc);
24+
entityType.ConfigurePropertiesXmlDocumentation(xDoc);
2425
}
2526

2627
return modelBuilder;

src/EntityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore/Extensions/MutableEntityTypeExtensions.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,34 @@ namespace BitzArt.XDoc;
1010
public static class MutableEntityTypeExtensions
1111
{
1212
/// <summary>
13-
/// Configures an entity and all its properties with comments from XML documentation.
13+
/// Configures XML documentation as comments for all properties of an entity type.
1414
/// </summary>
15-
/// <param name="entityType">The entity type to configure.</param>
16-
/// <param name="xDoc">The XDoc instance containing XML documentation.</param>
17-
public static void ConfigureEntityComments(this IMutableEntityType entityType, XDoc xDoc)
15+
/// <param name="entityType">The entity type whose properties should be configured with documentation.</param>
16+
/// <param name="xDoc">The XDoc instance containing XML documentation information.</param>
17+
/// <remarks>
18+
/// This method iterates through all properties of the entity type and applies
19+
/// XML documentation as comments to each property.
20+
/// </remarks>
21+
public static void ConfigurePropertiesXmlDocumentation(this IMutableEntityType entityType, XDoc xDoc)
1822
{
19-
entityType.ConfigureEntityTypeComment(xDoc);
20-
2123
var properties = entityType.GetProperties();
2224

2325
foreach (var property in properties)
2426
{
25-
entityType.ConfigureEntityPropertyComment(xDoc, property);
27+
entityType.ConfigurePropertyXmlDocumentation(xDoc, property);
2628
}
2729
}
2830

2931
/// <summary>
30-
/// Configures an entity type with a comment from its XML documentation.
32+
/// Configures XML documentation as a comment for an entity type.
3133
/// </summary>
32-
/// <param name="entityType">The entity type to configure.</param>
33-
/// <param name="xDoc">The XDoc instance containing XML documentation.</param>
34+
/// <param name="entityType">The entity type to configure with documentation.</param>
35+
/// <param name="xDoc">The XDoc instance containing XML documentation information.</param>
3436
/// <remarks>
3537
/// Comments are not applied to owned entities or entities without a table name.
38+
/// If no XML documentation exists for the entity type, no comment is set.
3639
/// </remarks>
37-
public static void ConfigureEntityTypeComment(this IMutableEntityType entityType, XDoc xDoc)
40+
public static void ConfigureEntityXmlDocumentation(this IMutableEntityType entityType, XDoc xDoc)
3841
{
3942
var typeDocumentation = xDoc.Get(entityType.ClrType);
4043

@@ -69,7 +72,7 @@ public static void ConfigureEntityTypeComment(this IMutableEntityType entityType
6972
/// <remarks>
7073
/// Comments are not applied to shadow properties or properties without documentation.
7174
/// </remarks>
72-
public static void ConfigureEntityPropertyComment(this IMutableEntityType entityType, XDoc xDoc, IMutableProperty property)
75+
public static void ConfigurePropertyXmlDocumentation(this IMutableEntityType entityType, XDoc xDoc, IMutableProperty property)
7376
{
7477
var isShadowProperty = property.IsShadowProperty();
7578

src/EntityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore/Extensions/OwnedNavigationBuilderExtensions.cs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,51 @@ namespace BitzArt.XDoc;
88
public static class OwnedNavigationBuilderExtensions
99
{
1010
/// <summary>
11-
/// Maps XML comments from an XDoc instance to an entity type and its properties.
11+
/// Configures XML documentation for the entity type represented by the owned navigation builder.
1212
/// </summary>
1313
/// <typeparam name="TOwnerEntity">The type of the owner entity.</typeparam>
1414
/// <typeparam name="TDependentEntity">The type of the dependent entity.</typeparam>
15-
/// <param name="builder">The owned navigation builder to extend.</param>
16-
/// <param name="xdoc">The XDoc instance containing XML comments to be mapped.</param>
17-
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
18-
public static OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> MapXmlComments<TOwnerEntity, TDependentEntity>(
19-
this OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> builder, XDoc xdoc)
15+
/// <param name="builder">The owned navigation builder to configure.</param>
16+
/// <param name="xdoc">The XML documentation container.</param>
17+
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
18+
public static OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> ConfigureEntityXmlDocumentation<TOwnerEntity,
19+
TDependentEntity>(
20+
this OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> builder,
21+
XDoc xdoc)
2022
where TOwnerEntity : class
2123
where TDependentEntity : class
2224
{
23-
var entityType = builder.Metadata.DeclaringEntityType;
25+
var entityType = builder.OwnedEntityType;
26+
27+
entityType.ConfigureEntityXmlDocumentation(xdoc);
2428

25-
entityType.ConfigureEntityTypeComment(xdoc);
29+
return builder;
30+
}
31+
32+
/// <summary>
33+
/// Configures XML documentation for all properties of the entity type represented by the owned navigation builder.
34+
/// </summary>
35+
/// <typeparam name="TOwnerEntity">The type of the owner entity.</typeparam>
36+
/// <typeparam name="TDependentEntity">The type of the dependent entity.</typeparam>
37+
/// <param name="builder">The owned navigation builder to configure.</param>
38+
/// <param name="xdoc">The XML documentation container.</param>
39+
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
40+
public static OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> ConfigurePropertiesXmlDocumentation<
41+
TOwnerEntity, TDependentEntity>(
42+
this OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> builder,
43+
XDoc xdoc)
44+
where TOwnerEntity : class
45+
where TDependentEntity : class
46+
{
47+
var entityType = builder.Metadata.DeclaringEntityType;
2648

2749
var properties = entityType.GetProperties();
2850

2951
foreach (var property in properties)
3052
{
31-
entityType.ConfigureEntityPropertyComment(xdoc, property);
53+
entityType.ConfigurePropertyXmlDocumentation(xdoc, property);
3254
}
3355

3456
return builder;
3557
}
36-
3758
}

0 commit comments

Comments
 (0)