AxaFrance.EFCore.SqlExpressions
1.0.0
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package AxaFrance.EFCore.SqlExpressions --version 1.0.0
NuGet\Install-Package AxaFrance.EFCore.SqlExpressions -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AxaFrance.EFCore.SqlExpressions" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AxaFrance.EFCore.SqlExpressions --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AxaFrance.EFCore.SqlExpressions, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AxaFrance.EFCore.SqlExpressions as a Cake Addin #addin nuget:?package=AxaFrance.EFCore.SqlExpressions&version=1.0.0 // Install AxaFrance.EFCore.SqlExpressions as a Cake Tool #tool nuget:?package=AxaFrance.EFCore.SqlExpressions&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EntityFrameworkCore.SqlExpressions
EntityFrameworkCore.SqlExpressions permet d'enregistrer des SqlExpressions simplement dans le mecanisme de rendu d' EntityFramework
EntityFrameworkCore.SqlExpressions.InMemory
Il est possible de faire simplement vos tests d'integration via cette librairie InMemory
Usage
Configuration
services.AddDbContextPool<NorthwindContext>(builder =>
builder.UseSqlServer("Data Source=localhost;Initial Catalog=Northwind;",
optionsBuilder =>
{
optionsBuilder.UseAddedExpressions(add =>
{
add(new SqlExpressionConfiguration(CustomSqlDbFunctionsExtensions.DeclaringType,
CustomSqlDbFunctionsExtensions.MyCustomMethodInfo,
arguments => new MyCustomSqlExpression(arguments)));
});
}));
DbFunctionExtensions
public static class CustomSqlDbFunctionsExtensions
{
public static Type DeclaringType { get; } = typeof(CustomSqlDbFunctionsExtensions);
public static MethodInfo MyCustomMethodInfo { get; } =
DeclaringType.GetMethod(nameof(MyCustom), new[] { typeof(DbFunctions), typeof(int) })!;
public static string MyCustom(this DbFunctions _, int value) =>
throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(MyCustom)));
}
Custom SqlExpression
public sealed class MyCustomSqlExpression : SqlExpression
{
private readonly SqlExpression[] sqlExpressions;
private static readonly StringTypeMapping relationalTypeMapping;
private static readonly SqlConstantExpression constantExpression;
private static readonly Type stringType;
public MyCustomSqlExpression(SqlExpression[] sqlExpressions) : base(stringType, relationalTypeMapping)
{
this.sqlExpressions = sqlExpressions.Prepend(constantExpression).ToArray();
}
static MyCustomSqlExpression()
{
relationalTypeMapping = new("nvarchar(max)", DbType.String);
stringType = typeof(string);
constantExpression = new SqlConstantExpression(Constant("-> ", stringType), relationalTypeMapping);
}
protected override Expression VisitChildren(ExpressionVisitor visitor)
{
return new SqlFunctionExpression("CONCAT", this.sqlExpressions, false,
this.sqlExpressions.Select(_ => false), stringType,
this.TypeMapping);
}
protected override void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.Visit(this);
}
}
Query
var result = dbContext.Regions.Select(r => EF.Functions.MyCustom(r.RegionId)).ToList();
License (MIT)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.EntityFrameworkCore (>= 7.0.7)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AxaFrance.EFCore.SqlExpressions:
Package | Downloads |
---|---|
AxaFrance.EFCore.SqlExpressions.InMemory
Use AxaFrance.EFCore.SqlExpressions.InMemory for create a custom SqlExpression on your application or on your integration test application |
GitHub repositories
This package is not used by any popular GitHub repositories.