Skip to content

Commit

Permalink
Merge pull request #16473 from hvitved/csharp/entity-framework-perf
Browse files Browse the repository at this point in the history
C#: Fix performance issue in EntityFramework modelling
  • Loading branch information
hvitved authored May 21, 2024
2 parents 1a20a62 + d9019f9 commit 60ee7fb
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 185 deletions.
23 changes: 9 additions & 14 deletions csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll
Original file line number Diff line number Diff line change
Expand Up @@ -437,26 +437,21 @@ module EntityFramework {
) {
this = dbSet.getDbContextClass() and
this.output(output, mapped, dbSet) and
result = dbSet.getFullName() + "#" + output.getMadRepresentation()
exists(string qualifier, string type, string name |
mapped.hasFullyQualifiedName(qualifier, type, name) and
result = getQualifiedName(qualifier, type, name)
)
}

pragma[nomagic]
string getSyntheticNameProj(Property mapped) { result = this.getSyntheticName(_, mapped, _) }
}

private class DbContextClassSetProperty extends Property {
private DbContextClass c;

DbContextClassSetProperty() { this = c.getADbSetProperty(_) }

/**
* Gets the fully qualified name for this.
*/
string getFullName() {
exists(string qualifier, string type, string name |
this.hasFullyQualifiedName(qualifier, type, name)
|
result = getQualifiedName(qualifier, type, name)
)
}

/**
* Gets the context class where this is a DbSet property.
*/
Expand Down Expand Up @@ -493,7 +488,7 @@ module EntityFramework {
exists(string name, Property mapped |
preservesValue = true and
c.input(input, mapped) and
name = c.getSyntheticName(_, mapped, _) and
name = c.getSyntheticNameProj(mapped) and
output = SummaryComponentStack::syntheticGlobal(name) and
model = "DbContextSaveChanges"
)
Expand All @@ -504,7 +499,7 @@ module EntityFramework {
* Add all possible synthetic global names.
*/
private class EFSummarizedCallableSyntheticGlobal extends SummaryComponent::SyntheticGlobal {
EFSummarizedCallableSyntheticGlobal() { this = any(DbContextClass c).getSyntheticName(_, _, _) }
EFSummarizedCallableSyntheticGlobal() { this = any(DbContextClass c).getSyntheticNameProj(_) }
}

private class DbContextSaveChangesRequiredSummaryComponentStack extends RequiredSummaryComponentStack
Expand Down
Loading

0 comments on commit 60ee7fb

Please sign in to comment.