Skip to content

EF Core updates #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
30 changes: 30 additions & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tests

on:
push:
branches:
- main
tags-ignore:
- '*'

jobs:
tests:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --no-restore --verbosity normal
Comment on lines +13 to +30

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
19 changes: 16 additions & 3 deletions XDoc.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.Tests", "tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.PlainText", "src\Render\BitzArt.XDoc.PlainText\BitzArt.XDoc.PlainText.csproj", "{95283F56-EFD3-4B32-AE26-4E486D186127}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.PlaintText.Tests", "tests\Render\BitzArt.XDoc.PlaintText.Tests\BitzArt.XDoc.PlaintText.Tests.csproj", "{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.PlainText.Tests", "tests\Render\BitzArt.XDoc.PlainText.Tests\BitzArt.XDoc.PlainText.Tests.csproj", "{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{4DF4BD72-775C-4D08-8192-DAD007669051}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -30,7 +30,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly.A", "tests\Mul
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly.B", "tests\MultiAssemblyTests\TestAssembly.B\TestAssembly.B.csproj", "{152D5D7F-EDF8-489C-B2BE-F22E5F63263F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.EntityFrameworkCore", "src\BitzArt.XDoc.EntityFrameworkCore\BitzArt.XDoc.EntityFrameworkCore.csproj", "{69E03C89-EA2B-4C47-BF61-70C5F9E56550}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.EntityFrameworkCore", "src\EntityFrameworkCore\BitzArt.XDoc.EntityFrameworkCore\BitzArt.XDoc.EntityFrameworkCore.csproj", "{69E03C89-EA2B-4C47-BF61-70C5F9E56550}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.EntityFrameworkCore.Tests", "tests\EntityFrameworkCore\BitzArt.XDoc.EntityFrameworkCore.Tests\BitzArt.XDoc.EntityFrameworkCore.Tests.csproj", "{3A197906-2E9F-48AE-BB67-092874629CBA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EntityFrameworkCore", "EntityFrameworkCore", "{5B807A9A-62ED-44BC-BB5F-86FE8923144B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EntityFrameworkCore", "EntityFrameworkCore", "{F12832C9-3988-40C4-B768-7028BC8273BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -66,6 +72,10 @@ Global
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Release|Any CPU.Build.0 = Release|Any CPU
{3A197906-2E9F-48AE-BB67-092874629CBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A197906-2E9F-48AE-BB67-092874629CBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A197906-2E9F-48AE-BB67-092874629CBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A197906-2E9F-48AE-BB67-092874629CBA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -80,6 +90,9 @@ Global
{401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31} = {616D63B3-7EF0-40FB-A404-33A221F65577}
{4398E200-26F9-4184-A943-47738FF5EB4E} = {401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31}
{152D5D7F-EDF8-489C-B2BE-F22E5F63263F} = {401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31}
{69E03C89-EA2B-4C47-BF61-70C5F9E56550} = {DE8DA5D7-65DB-4FE8-8CF9-52CEB9CE6648}
{69E03C89-EA2B-4C47-BF61-70C5F9E56550} = {5B807A9A-62ED-44BC-BB5F-86FE8923144B}
{3A197906-2E9F-48AE-BB67-092874629CBA} = {F12832C9-3988-40C4-B768-7028BC8273BE}
{5B807A9A-62ED-44BC-BB5F-86FE8923144B} = {DE8DA5D7-65DB-4FE8-8CF9-52CEB9CE6648}
{F12832C9-3988-40C4-B768-7028BC8273BE} = {616D63B3-7EF0-40FB-A404-33A221F65577}
EndGlobalSection
EndGlobal

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions src/BitzArt.XDoc/BitzArt.XDoc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,10 @@
<None Include="..\..\README.md" Pack="True" Visible="false" PackagePath="\"/>
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\BitzArt.XDoc.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\Release\BitzArt.XDoc.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>BitzArt.XDoc.Tests</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>BitzArt.XDoc.PlaintText.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>BitzArt.XDoc</RootNamespace>

<PackageId>BitzArt.XDoc.EntityFrameworkCore</PackageId>
<Authors>BitzArt</Authors>
<Description>Extension library that bridges XML documentation comments from C# code to Entity Framework Core database objects.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/BitzArt/xdoc</RepositoryUrl>
<PackageProjectUrl>https://github.com/BitzArt/xdoc</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>xdoc-logo.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\..\assets\xdoc-logo.png" Pack="True" Visible="false" PackagePath="\" />
<None Include="..\..\..\README.md" Pack="True" Visible="false" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\BitzArt.XDoc\BitzArt.XDoc.csproj"/>
<ProjectReference Include="..\..\Render\BitzArt.XDoc.PlainText\BitzArt.XDoc.PlainText.csproj"/>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>BitzArt.XDoc.EntityFrameworkCore.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using BitzArt.XDoc.PlainText;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace BitzArt.XDoc.EntityFrameworkCore;
namespace BitzArt.XDoc;

/// <summary>
/// Configures XML documentation comments for Entity Framework Core entities and their properties.
Expand Down Expand Up @@ -54,7 +53,7 @@ public void ConfigureComments(ModelBuilder modelBuilder)

if (isShadowProperty)
{
_logger.LogInformation($"Skipping shadow property [Name: {property.Name}]");
_logger.LogDebug($"Skipping shadow property [Name: {property.Name}]");

continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Linq.Expressions;

namespace BitzArt.XDoc;

/// <summary>
/// Extension methods for PropertyBuilder.
/// </summary>
[PublicAPI]
public static class PropertyBuilderExtensions
{
/// <summary>
/// Map property comment from XML documentation to the property.
/// </summary>
/// <param name="builder">
/// Property builder.
/// </param>
/// <param name="xdoc">
/// XDoc instance to use.
/// </param>
/// <param name="propertyExpression">
/// Expression to get the property name.
/// </param>
/// <typeparam name="TTargetEntity">
/// Entity type where the property is defined.
/// </typeparam>
/// <typeparam name="TTargetProperty">
/// Target property type.
/// </typeparam>
/// <returns></returns>
/*public static PropertyBuilder HasXmlComment<TTargetEntity, TTargetProperty>(
this PropertyBuilder builder,
XDoc xdoc,
Expression<Func<TTargetEntity, TTargetProperty>> propertyExpression)
{
var type = typeof(TTargetEntity);

//var expression = propertyExpression.Body as UnaryExpression;
//var operand = expression?.Operand as MemberExpression;

var operand = propertyExpression.Body as MemberExpression;
var propertyName = operand?.Member.Name;

if (string.IsNullOrWhiteSpace(propertyName))
{
return builder;
}

var propertyInfo = type.GetProperty(propertyName);

var comment = xdoc.Get(propertyInfo).ToPlainText();

if (!string.IsNullOrWhiteSpace(comment))
{
builder.HasComment(comment);
}

return builder;
}*/

public static EntityTypeBuilder<TEntity> HasPropertyComment<TEntity, TProperty>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
XDoc xdoc,
Expression<Func<TEntity, TProperty>> propertyExpression)
where TEntity : class
=> entityTypeBuilder.HasPropertyComment(xdoc, propertyExpression, propertyExpression);

public static EntityTypeBuilder<TEntity> HasPropertyComment<TEntity, TProperty, TCommentTargetEntity, TCommentTargetProperty>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
XDoc xdoc,
Expression<Func<TEntity, TProperty>> propertyExpression,
Expression<Func<TCommentTargetEntity, TCommentTargetProperty>> commentTargetPropertyExpression)
where TEntity : class
where TCommentTargetEntity : class
{
var operand = commentTargetPropertyExpression.Body as MemberExpression;
var propertyName = operand!.Member.Name;

if (string.IsNullOrWhiteSpace(propertyName))
{
throw new InvalidOperationException($"Property with name '{propertyName}' was not found.");
}

var commentTargetType = typeof(TCommentTargetEntity);
var targetPropertyInfo = commentTargetType.GetProperty(propertyName);

var comment = xdoc.Get(targetPropertyInfo).ToPlainText();

return entityTypeBuilder.HasPropertyComment(propertyExpression, comment);
}

public static EntityTypeBuilder<TEntity> HasPropertyComment<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
XDoc xdoc,
string propertyName)
where TEntity : class
=> entityTypeBuilder.HasPropertyComment(xdoc, typeof(TEntity), propertyName);

public static EntityTypeBuilder<TEntity> HasPropertyComment<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
XDoc xdoc,
Type targetEntityType,
string propertyName)
where TEntity : class
{
var propertyInfo = targetEntityType.GetProperty(propertyName);

var comment = xdoc.Get(propertyInfo).ToPlainText();

entityTypeBuilder.Property(propertyName).HasComment(comment);

return entityTypeBuilder;
}

public static EntityTypeBuilder<TEntity> HasPropertyComment<TEntity, TProperty>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
Expression<Func<TEntity, TProperty>> propertyExpression,
string? comment)
where TEntity : class
{
entityTypeBuilder.Property(propertyExpression).HasComment(comment);
return entityTypeBuilder;
}
}
Loading