Skip to content

Commit 4af53b1

Browse files
authored
Fix errors when using Microsoft. Data. Sqlite (#237)
1 parent f82b316 commit 4af53b1

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed

sample/SmartSql.Sample.AspNetCore/Controllers/UserController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public IEnumerable<User> Query(int taken = 10)
7676
return _userRepository.Query(taken);
7777
}
7878

79-
[HttpGet]
79+
[HttpGet("/[controller]/QueryAsync")]
8080
public async Task<IEnumerable<User>> QueryAsync(int taken = 10)
8181
{
8282
return await _userRepository.QueryAsync(taken);

sample/SmartSql.Sample.AspNetCore/SmartSql.Sample.AspNetCore.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="SkyAPM.Agent.AspNetCore" Version="0.9.0" />
9-
<PackageReference Include="SkyAPM.Diagnostics.SmartSql" Version="0.9.0" />
10-
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
11-
<PackageReference Include="System.Data.SQLite" Version="1.0.115.5" />
8+
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.10" />
9+
<PackageReference Include="SkyAPM.Agent.AspNetCore" Version="2.1.0" />
10+
<PackageReference Include="SkyAPM.Diagnostics.SmartSql" Version="2.1.0" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

sample/SmartSql.Sample.AspNetCore/Startup.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
9+
using Microsoft.OpenApi.Models;
810
using SmartSql.InvokeSync.RabbitMQ;
911
using SmartSql.Sample.AspNetCore.Service;
1012
using Swashbuckle.AspNetCore.Swagger;
@@ -24,7 +26,7 @@ public Startup(IConfiguration configuration)
2426
public IServiceProvider ConfigureServices(IServiceCollection services)
2527
{
2628
// services.AddSkyApmExtensions().AddSmartSql();
27-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
29+
services.AddControllers();
2830
services
2931
.AddSmartSql((sp, builder) =>
3032
{
@@ -38,17 +40,17 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
3840
{
3941
o.AssemblyString = "SmartSql.Sample.AspNetCore";
4042
o.Filter = (type) => type.Namespace == "SmartSql.Sample.AspNetCore.DyRepositories";
41-
})
42-
.AddInvokeSync(options => { })
43-
.AddRabbitMQPublisher(options =>
44-
{
45-
options.HostName = "localhost";
46-
options.UserName = "guest";
47-
options.Password = "guest";
48-
options.Exchange = "smartsql";
49-
options.RoutingKey = "smartsql.sync";
50-
5143
});
44+
// .AddInvokeSync(options => { })
45+
// .AddRabbitMQPublisher(options =>
46+
// {
47+
// options.HostName = "localhost";
48+
// options.UserName = "guest";
49+
// options.Password = "guest";
50+
// options.Exchange = "smartsql";
51+
// options.RoutingKey = "smartsql.sync";
52+
//
53+
// });
5254
// .AddRabbitMQSubscriber(options =>
5355
// {
5456
// options.HostName = "localhost";
@@ -74,13 +76,13 @@ private void RegisterConfigureSwagger(IServiceCollection services)
7476
{
7577
services.AddSwaggerGen(c =>
7678
{
77-
c.SwaggerDoc("v1", new Info
79+
c.SwaggerDoc("v1", new OpenApiInfo()
7880
{
7981
Title = "SmartSql.Sample.AspNetCore",
8082
Version = "v1",
81-
Contact = new Contact
83+
Contact = new OpenApiContact
8284
{
83-
Url = "https://github.com/Smart-Kit/SmartSql",
85+
Url = new Uri("https://github.com/Smart-Kit/SmartSql"),
8486
Email = "[email protected]",
8587
Name = "SmartSql"
8688
},
@@ -91,23 +93,27 @@ private void RegisterConfigureSwagger(IServiceCollection services)
9193
}
9294

9395
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
94-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
96+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
9597
{
9698
if (env.IsDevelopment())
9799
{
98100
app.UseDeveloperExceptionPage();
99101
}
100102

101-
app.ApplicationServices.UseSmartSqlSync();
102-
app.ApplicationServices.UseSmartSqlSubscriber((syncRequest) =>
103-
{
104-
Console.Error.WriteLine(syncRequest.Scope);
105-
});
103+
// app.ApplicationServices.UseSmartSqlSync();
104+
// app.ApplicationServices.UseSmartSqlSubscriber((syncRequest) =>
105+
// {
106+
// Console.Error.WriteLine(syncRequest.Scope);
107+
// });
106108

107-
app.UseMvc();
108-
app.UseStaticFiles();
109109
app.UseSwagger(c => { });
110110
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "SmartSql.Sample.AspNetCore"); });
111+
112+
app.UseRouting();
113+
app.UseEndpoints(endpoints =>
114+
{
115+
endpoints.MapControllers();
116+
});
111117
}
112118
}
113119
}

src/SmartSql/DataSource/DbProviderManager.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,15 @@ public bool TryInit(ref DbProvider dbProvider)
122122

123123
dbProvider.Type = dbProviderCache.Type;
124124
dbProvider.Factory = dbProviderCache.Factory;
125+
125126
var cmdBuilder = dbProvider.Factory.CreateCommandBuilder();
126-
dbProvider.ParameterNamePrefix = cmdBuilder.QuotePrefix;
127-
dbProvider.ParameterNameSuffix = cmdBuilder.QuoteSuffix;
128-
cmdBuilder.Dispose();
127+
if (cmdBuilder != null)
128+
{
129+
dbProvider.ParameterNamePrefix = cmdBuilder.QuotePrefix;
130+
dbProvider.ParameterNameSuffix = cmdBuilder.QuoteSuffix;
131+
cmdBuilder.Dispose();
132+
}
133+
129134
return true;
130135
}
131136

0 commit comments

Comments
 (0)