Уменьшение длины псевдонима таблицы в Firebird EntityFrameworkCore - PullRequest
1 голос
/ 13 апреля 2019

При обращении к столбцу условия проходит через несколько таблиц, для объединенных таблиц генерируется очень длинный псевдоним.В Firebird максимальный идентификатор ограничен 31 символом.Можно ли повлиять на размер генерируемых псевдонимов?

Я использую .net core 2.1 и FirebirdSql.EntityFrameworkCore.Firebird 6.6.0

Абстрактный пример:

class Table1
{
    int id
    int value
    int idTable2
    [ForeignKey("idTable2")]
    Table2 table2
}
class Table2
{
    int id
    int idTable3
    [ForeignKey("idTable3")]
    Table3 table3
}
class Table3
{
    int id
    bool condition
}

Когда я делаю:

var result = Table1.where(t => t.table2.table3.condition).select(t => value)

генерирует запрос:

SELECT
    value
FROM
    Table1 AS "r"
    LEFT JOIN Table2 AS "r.Table2" ON "r"."idTable2" = "r.Table2"."id"
    LEFT JOIN Table3 AS "r.Table2.Table3" ON "r.Table2"."IdTable3" = "r.Table2.Table3"."id"
WHERE
    "r.Table2.Table3"."condition"

Можно ли сделать псевдонимы объединяемой таблицы в качестве основной?Как "а", "б" и т. Д.

1 Ответ

0 голосов
/ 27 июня 2019

Это обходной путь.Код должен быть реализован Поставщиком.

Создайте два класса: MyFbSqlQueryCompilationContext и MyFbSqlQueryCompilationContextFactory (см. Ниже).

Где вы устанавливаете DbContext:

        optionsBuilder.UseFirebird(connectionString)
            .ReplaceService<IQueryCompilationContextFactory, MyFbSqlQueryCompilationContextFactory>();


public class MyFbSqlQueryCompilationContext : RelationalQueryCompilationContext
{

    public MyFbSqlQueryCompilationContext(
        QueryCompilationContextDependencies dependencies,
        ILinqOperatorProvider linqOperatorProvider,
        IQueryMethodProvider queryMethodProvider,
        bool trackQueryResults)
        : base(
            dependencies,
            linqOperatorProvider,
            queryMethodProvider,
            trackQueryResults)
    {
    }

    public override int MaxTableAliasLength => 31;
}

public class MyFbSqlQueryCompilationContextFactory : RelationalQueryCompilationContextFactory
{
    public MyFbSqlQueryCompilationContextFactory(
        QueryCompilationContextDependencies dependencies,
        RelationalQueryCompilationContextDependencies relationalDependencies)
        : base(dependencies, relationalDependencies)
    {
    }

    public override QueryCompilationContext Create(bool async)
        => async
            ? new MyFbSqlQueryCompilationContext(
                Dependencies,
                new AsyncLinqOperatorProvider(),
                new AsyncQueryMethodProvider(),
                TrackQueryResults)
            : new MyFbSqlQueryCompilationContext(
                Dependencies,
                new LinqOperatorProvider(),
                new QueryMethodProvider(),
                TrackQueryResults);
}
...