【发布时间】:2022-08-14 19:31:58
【问题描述】:
我在 ASP core 6 MVC 中设置我的 SQLKATA 时遇到问题,Sqlkata 网站中的示例代码使用 startup.cs 正确设置编译器。现在它的 ASP Core 6 不再使用启动,而是使用 program.cs w/c 与 sqlkata w/c 使用的代码不兼容:
services.Add<QueryFactory>(() => {
// In real life you may read the configuration dynamically
var connection = new MySqlConnection(
\"Host=localhost;Port=3306;User=user;Password=secret;Database=Users;SslMode=None\"
);
var compiler = new MySqlCompiler();
return new QueryFactory(connection, compiler);
});
我使用了 builder.Services ,但它不接受 Add 选项。知道什么问题和做什么?
-
“不接受”是什么意思?您是否缺少
using声明? -
是的,我确实使用过 SqlKata.Compilers;使用 SqlKata.Execution;
-
我把它放在 program.cs builder.Services.Add<QueryFactory> ( ( ) => { // 在现实生活中你可以动态读取配置 var connection = new MySqlConnection ( \"Host=localhost;Port=3306;User =user;Password=secret;Database=Users;SslMode=None\" ); var compiler = new MySqlCompiler (); return new QueryFactory (connection, compiler); 但我收到一条通知,说明它 Iservice 集合不包含添加