Linq2db: Sending SQL queries through custom connector.

Created on 27 Jan 2020  ·  4Comments  ·  Source: linq2db/linq2db

В новом проекте появилось ограничение - все запросы к БД должны выполняться через специальный компонент "MySuperDbConnection". В компоненте реализован набор методов ExecuteScalar(DbCommand), ExecuteReader(DbCommand) и пр. Целевая БД - postgres.

Можно ли как то попросить linq2db выполнять все запросы через этот компонент?

Цель - использовать всю мощь linq2db для формирования статически типизованных запросов, а выполнять их через свою библиотеку.

question

Most helpful comment

@SergeyA, also we have global interceptor. Maybe it can help

You can inject here:
https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DbCommandProcessor/DbCommandProcessorExtensions.cs#L22

Implement IDbCommandProcessor and assign this static property.

All 4 comments

You should loot at DataConnection constructors that accept IDbConnection/Func<IDbConnection>. There you need to pass your MySuperDbConnection or adapter to MySuperDbConnection.

Also disable use of npgsql-specific API: https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Common/Configuration.cs

Note that because execute methods belong to DbCommand, you will need to implement own DbCommand and return it from custom connection.

@SergeyA, also we have global interceptor. Maybe it can help

You can inject here:
https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DbCommandProcessor/DbCommandProcessorExtensions.cs#L22

Implement IDbCommandProcessor and assign this static property.

@SergeyA please use English if possible when publishing an issue. Thank you!

Was this page helpful?
0 / 5 - 0 ratings