Skip to content

Commit

Permalink
#194 initialise sets in dbcontext for NRT support (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvreony committed Jan 6, 2022
1 parent da36690 commit 4333b0e
Showing 1 changed file with 6 additions and 12 deletions.
Expand Up @@ -142,25 +142,19 @@ private PropertyDeclarationSyntax[] GetPropertyDeclarations(IEntityGenerationMod
private PropertyDeclarationSyntax GetPropertyDeclaration(
IEntityGenerationModel generationModelEntityGenerationModel)
{
var accessorList = new[]
{
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
};
var setType = SyntaxFactory.ParseTypeName($"Set<EfModels.{generationModelEntityGenerationModel.ClassName}EfModel>");
var setCreation = SyntaxFactory.InvocationExpression(setType);
var arrowExpression = SyntaxFactory.ArrowExpressionClause(setCreation);

var summary = GetSummary(new[] { $"Gets or Sets the DBSet for {generationModelEntityGenerationModel.ClassName}" });
var summary = GetSummary(new[] { $"Gets the DBSet for {generationModelEntityGenerationModel.ClassName}" });

var type = SyntaxFactory.ParseTypeName($"DbSet<EfModels.{generationModelEntityGenerationModel.ClassName}EfModel>");
var identifier = generationModelEntityGenerationModel.ClassName;

var result = SyntaxFactory.PropertyDeclaration(type, identifier)
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
.WithAccessorList(
SyntaxFactory.AccessorList(
SyntaxFactory.List(accessorList)
))
.WithExpressionBody(arrowExpression)
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
.WithLeadingTrivia(summary);

return result;
Expand Down

0 comments on commit 4333b0e

Please sign in to comment.