Skip to content

Commit

Permalink
Merge pull request #8 from longxianghui/revert-5-origin
Browse files Browse the repository at this point in the history
Revert "升级到 支持efcore3.1 添加sqlite支持"
  • Loading branch information
longxianghui authored May 25, 2022
2 parents 9f5df71 + 7afa9f1 commit d22cf02
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 252 deletions.
4 changes: 2 additions & 2 deletions Leo.Chimp.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
# Visual Studio 15
VisualStudioVersion = 15.0.28307.705
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Leo.Chimp", "src\Leo.Chimp\Leo.Chimp.csproj", "{AE57FE9E-110F-4BBD-AF58-243A37E334C3}"
EndProject
Expand Down
5 changes: 1 addition & 4 deletions example/Leo.Chimp.Domain/Entities/School.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace Leo.Chimp.Domain.Entities
{
[Table("school")]
public class School
{
public School()
{
Students = new List<Student>();
}
[Key]

public Guid Id { get; set; }
public string Name { get; set; }

Expand Down
4 changes: 0 additions & 4 deletions example/Leo.Chimp.Domain/Entities/Student.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using System.Text.RegularExpressions;

namespace Leo.Chimp.Domain.Entities
{
[Table("student")]
public class Student : IEntity
{
[Key]
public Guid Id { get; set; }
public string Name { get; set; }
public Guid SchoolId { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions example/Leo.Chimp.Domain/Leo.Chimp.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion example/Leo.Chimp.Example/Leo.Chimp.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Leo.Chimp.Domain\Leo.Chimp.Domain.csproj" />
</ItemGroup>
Expand Down
10 changes: 3 additions & 7 deletions example/Leo.Chimp.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Leo.Chimp.Example
Expand All @@ -18,11 +17,8 @@ public static void Main(string[] args)
CreateWebHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateWebHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
17 changes: 4 additions & 13 deletions example/Leo.Chimp.Example/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand All @@ -27,29 +26,21 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddChimp<ChimpDbContext>(
/*opt => opt.UseSqlServer("Server=10.0.0.99;Database=Chimp;Uid=sa;Pwd=Fuluerp123")*/
opt => opt.UseMySql("Server=192.168.5.5;Database=Chimp;Uid=root;Pwd='luodaoyi';SslMode=none")
opt => opt.UseSqlServer("Server=10.0.0.99;Database=Chimp;Uid=sa;Pwd=Fuluerp123")
);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);
});
app.UseMvc();
}
}
}
23 changes: 0 additions & 23 deletions sqlscript/sqllite/script.sql

This file was deleted.

16 changes: 0 additions & 16 deletions src/Leo.Chimp/DapperAdapter/SqliteAdapter.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/Leo.Chimp/EfCoreRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
using System.Collections.Generic;
using System.Data;
Expand Down Expand Up @@ -32,7 +31,7 @@ public TEntity GetById(object id)

return Entities.Find(id);
}
public ValueTask<TEntity> GetByIdAsync(object id)
public Task<TEntity> GetByIdAsync(object id)
{
if (id == null)
throw new ArgumentNullException("id");
Expand All @@ -57,7 +56,7 @@ public void Insert(IEnumerable<TEntity> entities)
Entities.AddRange(entities);
}

public ValueTask<EntityEntry<TEntity>> InsertAsync(TEntity entity)
public Task InsertAsync(TEntity entity)
{
if (entity == null)
throw new ArgumentNullException("entity");
Expand Down
5 changes: 2 additions & 3 deletions src/Leo.Chimp/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;

namespace Leo.Chimp
Expand All @@ -31,7 +30,7 @@ public interface IRepository<TEntity> where TEntity : class
/// </summary>
/// <param name="id">主键</param>
/// <returns>Entity</returns>
ValueTask<TEntity> GetByIdAsync(object id);
Task<TEntity> GetByIdAsync(object id);

/// <summary>
/// Table Tracking
Expand Down Expand Up @@ -61,7 +60,7 @@ public interface IRepository<TEntity> where TEntity : class
/// 添加实体
/// </summary>
/// <param name="entity">Inserted entity</param>
ValueTask<EntityEntry<TEntity>> InsertAsync(TEntity entity);
Task InsertAsync(TEntity entity);

/// <summary>
/// InsertAsync
Expand Down
3 changes: 1 addition & 2 deletions src/Leo.Chimp/KingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class KingOptions
public enum DbType
{
MSSQL,
MYSQL,
SQLITE
MYSQL
}

}
21 changes: 10 additions & 11 deletions src/Leo.Chimp/Leo.Chimp.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageProjectUrl>https://github.com/luodaoyi/chimp</PackageProjectUrl>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageProjectUrl>https://github.com/longxianghui/chimp</PackageProjectUrl>
<LangVersion>7.3</LangVersion>
<Version>3.0.0</Version>
<Authors>luodaoyi</Authors>
<Version>2.1.2</Version>
<Authors>longxianghui</Authors>
<Description>ef and dapper repository.</Description>
<PackageTags>repository;unit of work;ef;dapper;</PackageTags>
<RepositoryUrl>https://github.com/luodaoyi/chimp</RepositoryUrl>
<RepositoryUrl>https://github.com/longxianghui/chimp</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />
<PackageReference Include="Dapper" Version="2.0.30" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.11" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" />
</ItemGroup>

</Project>
6 changes: 2 additions & 4 deletions src/Leo.Chimp/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ public async Task<PagedList<TEntity>> QueryPagedListAsync<TEntity>(int pageIndex
ISqlAdapter sqlAdapter = null;
if (_context.Database.IsMySql())
sqlAdapter = new MysqlAdapter();
else if(_context.Database.IsSqlServer())
if (_context.Database.IsSqlServer())
sqlAdapter = new SqlServerAdapter();
else if(_context.Database.IsSqlite())
sqlAdapter = new SqliteAdapter();
else
if (sqlAdapter == null)
throw new Exception("Unsupported database type");
pageSql = sqlAdapter.PagingBuild(ref partedSql, pageSqlArgs, (pageIndex - 1) * pageSize, pageSize);
var sqlCount = PagingUtil.GetCountSql(partedSql);
Expand Down
8 changes: 4 additions & 4 deletions test/Leo.Chimp.Test/ChimpDbContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ namespace Leo.Chimp.Test

public class ChimpDbContextTest
{
private readonly DbType dbType;

private readonly IUnitOfWork _unitOfWork;
private readonly ISchoolRepository _schoolRepository;
public ChimpDbContextTest()
{
var services = new ServiceCollection();
dbType = DbType.MYSQL;
InitChimpTestDb.Start(services, dbType);
services.AddChimp<ChimpDbContext>(opt =>
{
opt.UseMySql("server = 10.0.0.146;database=chimp;uid=root;password=123456;");
});
var sp = services.BuildServiceProvider();
_unitOfWork = sp.GetRequiredService<IUnitOfWork>();
_schoolRepository = sp.GetRequiredService<ISchoolRepository>();
Expand Down
Loading

0 comments on commit d22cf02

Please sign in to comment.