36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
|
|
using Microsoft.EntityFrameworkCore.Query;
|
|||
|
|
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
|||
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
|
|||
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace APT.Infrastructure.EF
|
|||
|
|
{
|
|||
|
|
public class CustomNpgsqlQuerySqlGenerator : NpgsqlQuerySqlGenerator
|
|||
|
|
{
|
|||
|
|
public CustomNpgsqlQuerySqlGenerator(QuerySqlGeneratorDependencies dependencies, bool reverseNullOrderingEnabled, Version postgresVersion)
|
|||
|
|
: base(dependencies, reverseNullOrderingEnabled,postgresVersion) { }
|
|||
|
|
protected override Expression VisitTable(TableExpression tableExpression)
|
|||
|
|
{
|
|||
|
|
var result = base.VisitTable(tableExpression);
|
|||
|
|
Sql.Append(" WITH (NOLOCK)");
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class CustomNpgsqlQuerySqlGeneratorFactory : NpgsqlQuerySqlGeneratorFactory
|
|||
|
|
{
|
|||
|
|
private readonly QuerySqlGeneratorDependencies _dependencies;
|
|||
|
|
public CustomNpgsqlQuerySqlGeneratorFactory(QuerySqlGeneratorDependencies dependencies, INpgsqlOptions npgsqlOptions)
|
|||
|
|
: base(dependencies, npgsqlOptions)
|
|||
|
|
{
|
|||
|
|
_dependencies = dependencies;
|
|||
|
|
}
|
|||
|
|
public override QuerySqlGenerator Create() =>
|
|||
|
|
new CustomNpgsqlQuerySqlGenerator(_dependencies,true,new Version(12,2));
|
|||
|
|
}
|
|||
|
|
}
|