前言

我使用的是oracle 11版本的数据库,但我使用ef core 2.1,在使用linq进行分页会生成oracle 12语法的sql,在oracle 11下会运行报错。

在dbcontext下onconfiguring指定使用oracle 11版本
optionsbuilder.useoracle(connectionstring,p => p.useoraclesqlcompatibility("11"));
默认生成12版本的sql
select "p"."keyid"
from "hd_form" "p"
where "p"."earea" is null 
offset :p_0 rows fetch next :p_1 rows only
指定版本为11的sql
select k0 "keyid" from(
    select "m2".*, rownum r2 from
    (
        select "p"."keyid" k0
        from "hd_form" "p"
        where ("p"."earea" is null )
    ) "m2"
) "m1"
where r2 > :p_0
and r2 <= (:p_0 + :p_1)

附加 日志输出sql
1、通过nuget添加引用 microsoft.extensions.logging.debug
2、在ef的dbcontext文件引用
using microsoft.extensions.logging;
using microsoft.extensions.logging.debug;
3、日志工厂
public static readonly loggerfactory myloggerfactory = new loggerfactory(new[] {
            new debugloggerprovider((category, level) => category == dbloggercategory.database.command.name && level >= loglevel.information)
        });
4、在dbcontext下onconfiguring添加
optionsbuilder.useloggerfactory(myloggerfactory);