-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory issue with expression constants (#133)
* Bump sample project to .NET 8 * Add method to replace constant dynamic values * Bump version to 3.0.1 * Update github workflows to use .NET 8 --------- Co-authored-by: Nino Schoch <[email protected]>
- Loading branch information
Showing
7 changed files
with
79 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
12 changes: 6 additions & 6 deletions
12
DataTables.NetStandard.Enhanced.Sample/DataTables.NetStandard.Enhanced.Sample.csproj
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,24 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace DataTables.NetStandard.Enhanced.Util | ||
{ | ||
public static class ExpressionHelper | ||
{ | ||
/// <summary> | ||
/// Creates a constant filter expression of the given <paramref name="value"/> and converts the type to the given <paramref name="type"/>. | ||
/// </summary> | ||
/// <param name="value"></param> | ||
/// <param name="type"></param> | ||
internal static Expression CreateConstantFilterExpression(object value, Type type) | ||
{ | ||
// The value is converted to anonymous function only returning the value itself. | ||
Expression<Func<object>> valueExpression = () => value; | ||
|
||
// Afterwards only the body of the function, which is the value, is converted to the delivered type. | ||
// Therefore no Expression.Constant is necessary which lead to memory leaks, because EFCore caches such constants. | ||
// Caching constants is not wrong, but creating constants of dynamic search values is wrong. | ||
return Expression.Convert(valueExpression.Body, type); | ||
} | ||
} | ||
} |