-
Notifications
You must be signed in to change notification settings - Fork 0
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
EF Core updates #17
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
79c398b
EF Core updates
YuriyDurov 0b67c38
Add badges
YuriyDurov 0f02a41
Add comments
a-gubskiy aa26c16
Format code
a-gubskiy 279da71
Add comments
a-gubskiy 931d06f
Format code
a-gubskiy 0243259
Implement HasPropertyComment
a-gubskiy 319811b
Add test
a-gubskiy 980fb55
Update test
a-gubskiy e0802e3
Add HasPropertyComment
a-gubskiy 773ac42
Update GetComment
a-gubskiy 3f146cb
Add test
a-gubskiy 7f6001c
Simplify HasPropertyComment
a-gubskiy b9048fb
Format code
a-gubskiy 85e5e98
Format code
a-gubskiy 3068f08
Update MySecondClass
a-gubskiy 015e358
Add shadow property tests
a-gubskiy b247a6f
Arrange extension methods.
a-gubskiy bb1dc58
Cleanup XDocHelper
a-gubskiy c60f315
Cleanup EntitiesCommentConfigurator
a-gubskiy 36cd57a
Update XDocExtensions
a-gubskiy 398d9e7
Update XDocExtensions signature
a-gubskiy 9e77a70
Update comment
a-gubskiy f4a37b4
Update documentation retrieving from xdoc
a-gubskiy e0954f5
Merge remote-tracking branch 'origin/ef-core-entity-builder-extension…
a-gubskiy 0b6f6b3
Merge remote-tracking branch 'origin/main' into ef-core-entity-builde…
a-gubskiy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
src/BitzArt.XDoc.EntityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore.csproj
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
src/BitzArt.XDoc.EntityFrameworkCore/Extensions/PropertyBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...ityFrameworkCore/BitzArt.XDoc.EntityFrameworkCore/Extensions/PropertyBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium