添加mysql 支持
This commit is contained in:
parent
1a7be7a6af
commit
5b3cea0672
@ -19,12 +19,17 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Core\JiShe.CollectBus.Core.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
|
||||
},
|
||||
|
||||
"TCP": {
|
||||
"Port": 10500
|
||||
},
|
||||
|
||||
@ -13,11 +13,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TouchSocket" Version="2.1.5" />
|
||||
<PackageReference Include="TouchSocket.Hosting" Version="2.1.5" />
|
||||
<PackageReference Include="TouchSocket" Version="2.1.9" />
|
||||
<PackageReference Include="TouchSocket.Hosting" Version="2.1.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
16
JiShe.CollectBus.EntityFrameworkCore/AuditLogs/AuditLog.cs
Normal file
16
JiShe.CollectBus.EntityFrameworkCore/AuditLogs/AuditLog.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.EntityFrameworkCore.Entities;
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore.AuditLogs
|
||||
{
|
||||
public class AuditLog : EntityBase<Guid>,ICreationAudited<long?>
|
||||
{
|
||||
public string Re
|
||||
public long? CreatorId { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
}
|
||||
}
|
||||
29
JiShe.CollectBus.EntityFrameworkCore/CollectBusDbContext.cs
Normal file
29
JiShe.CollectBus.EntityFrameworkCore/CollectBusDbContext.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore
|
||||
{
|
||||
public class CollectBusDbContext : DbContext
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
|
||||
private DbSet<Device> Devices { set; get; }
|
||||
|
||||
public CollectBusDbContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseMySql(_configuration.GetConnectionString("Default"),ServerVersion.AutoDetect(_configuration.GetConnectionString("Default")));
|
||||
}
|
||||
}
|
||||
}
|
||||
26
JiShe.CollectBus.EntityFrameworkCore/Device.cs
Normal file
26
JiShe.CollectBus.EntityFrameworkCore/Device.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.EntityFrameworkCore.Entities;
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore
|
||||
{
|
||||
public class Device : EntityBase<Guid>, ICreationAudited<long?>, IModificationAudited<long?>
|
||||
{
|
||||
public string DeviceNo { get; set; }
|
||||
public DeviceStatusEnum DeviceStatus { get; set; }
|
||||
public long? CreatorId { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
public long? LastModifierId { get; set; }
|
||||
public DateTime? LastModificationTime { get; set; }
|
||||
}
|
||||
|
||||
public enum DeviceStatusEnum
|
||||
{
|
||||
Unknown = 0,
|
||||
Online = 1,
|
||||
Offline = 2,
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
60
JiShe.CollectBus.EntityFrameworkCore/Migrations/20241022055227_Init.Designer.cs
generated
Normal file
60
JiShe.CollectBus.EntityFrameworkCore/Migrations/20241022055227_Init.Designer.cs
generated
Normal file
@ -0,0 +1,60 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using JiShe.CollectBus.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore.Migrations
|
||||
{
|
||||
[DbContext(typeof(CollectBusDbContext))]
|
||||
[Migration("20241022055227_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("JiShe.CollectBus.EntityFrameworkCore.Device", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("CreatorId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("DeviceNo")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("DeviceStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("LastModificationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("LastModifierId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Devices");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Init : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Devices",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
DeviceNo = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
DeviceStatus = table.Column<int>(type: "int", nullable: false),
|
||||
CreatorId = table.Column<long>(type: "bigint", nullable: true),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
LastModifierId = table.Column<long>(type: "bigint", nullable: true),
|
||||
LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Devices", x => x.Id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Devices");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using JiShe.CollectBus.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore.Migrations
|
||||
{
|
||||
[DbContext(typeof(CollectBusDbContext))]
|
||||
partial class CollectBusDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("JiShe.CollectBus.EntityFrameworkCore.Device", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("CreatorId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("DeviceNo")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("DeviceStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("LastModificationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("LastModifierId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Devices");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ using JiShe.CollectBus.EntityFrameworkCore.Entities;
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore.Repositories
|
||||
{
|
||||
public interface IRepository<TDbContext, TEntity, TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
|
||||
public interface IRepository<TEntity, TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
|
||||
{
|
||||
IQueryable<TEntity> GetAll(params Expression<Func<TEntity, object>>[] propertySelectors);
|
||||
|
||||
|
||||
@ -10,15 +10,14 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JiShe.CollectBus.EntityFrameworkCore.Repositories
|
||||
{
|
||||
public class Repository<TDbContext, TEntity, TPrimaryKey> : IRepository<TDbContext, TEntity, TPrimaryKey>
|
||||
public class Repository<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
|
||||
where TEntity : class, IEntity<TPrimaryKey>
|
||||
where TDbContext : DbContext
|
||||
{
|
||||
public virtual DbContext DbContext { private set; get; }
|
||||
public virtual CollectBusDbContext DbContext { private set; get; }
|
||||
|
||||
public virtual DbSet<TEntity> Table => DbContext.Set<TEntity>();
|
||||
|
||||
public Repository(DbContext dbContext)
|
||||
public Repository(CollectBusDbContext dbContext)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="TouchSocket" Version="2.1.5" />
|
||||
<PackageReference Include="TouchSocket" Version="2.1.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user