ArielCore.MixedDataBase
1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ArielCore.MixedDataBase --version 1.0.2
NuGet\Install-Package ArielCore.MixedDataBase -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArielCore.MixedDataBase" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ArielCore.MixedDataBase" Version="1.0.2" />
<PackageReference Include="ArielCore.MixedDataBase" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ArielCore.MixedDataBase --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ArielCore.MixedDataBase, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ArielCore.MixedDataBase@1.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ArielCore.MixedDataBase&version=1.0.2
#tool nuget:?package=ArielCore.MixedDataBase&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
使用步骤:
- 首先添加nuget包ArielCore.MixedDataBase
- 在startup.cs或Program.cs或入口处添加如下
services.AddCoreDbContext<MySqlSjDbContext>("server=localhost;port=3306;user id=root;password=123456;database=cztest;charset=utf8mb4;ConnectionReset=false;AllowUserVariables=true;default command timeout=600;", DataBaseType.MySql);
- 添加文件MySqlSjDbContext.cs文件
namespace API.Domain.DataAcces
{
/// <summary>
/// DbContext
/// </summary>
public class MySqlSjDbContext : DbContext
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="options"></param>
public MySqlSjDbContext(DbContextOptions options) : base(options)
{
Database.EnsureCreated();
}
/// <summary>
/// 用户
/// </summary>
public DbSet<UserEntity> Users { get; set; }
/// <summary>
/// OnModelCreating
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
#region 注册领域模型与数据库的映射关系
//modelBuilder.ApplyConfiguration(new UserSourceEntityTypeConfiguration());
#endregion
}
}
}
- 添加文件UserEntity.cs
namespace API.Domain.Entities.UserAggregate
{
/// <summary>
/// 用户
/// </summary>
[Table("t_user")]
public class UserEntity : CommonBaseEntity
{
/// <summary>
/// 构造函数
/// </summary>
public UserEntity() { }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="loginName"></param>
public UserEntity(string loginName)
{
LoginName = loginName;
UserName = LoginName;
CreatedTime = DateTime.Now;
UpdatedTime = DateTime.Now;
IsDeleted = false;
}
/// <summary>
/// 用户名称
/// </summary>
[Required]
[MaxLength(50)]
public string UserName { get; set; }
/// <summary>
/// 登录名称
/// </summary>
[Required]
[MaxLength(50)]
public string LoginName { get; set; }
/// <summary>
/// 登录密码
/// </summary>
[Required]
[MaxLength(150)]
public string LoginPwd { get; set; }
/// <summary>
/// Email
/// </summary>
[MaxLength(50)]
public string Email { get; set; }
#region 关联属性,有需要类似下面添加
/// <summary>
/// 用户-部门
/// </summary>
[NotMapped]
public virtual ICollection<UserDepartmentEntity> UserDepartments { get; set; }
/// <summary>
/// 部门id集合
/// </summary>
[NotMapped]
public List<string> DepartmentIds { get; set; }
/// <summary>
/// 部门名称集合
/// </summary>
[NotMapped]
public List<string> DepartmentNames { get; set; }
#endregion
}
}
- 添加EntityBase.cs文件
namespace API.Domain.Entities
{
/// <summary>
/// 实体基类
/// </summary>
public class CommonBaseEntity : EntityBase<string>
{
/// <summary>
/// 主键Id
/// </summary>
[MaxLength(50)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
//[ExplicitKey]
public override string Id { get; set; } = GetId();
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreatedTime { get; set; } = DateTime.Now;
/// <summary>
/// 创建人
/// </summary>
[MaxLength(50)]
public string? CreatedBy { get; set; } = default!;
/// <summary>
/// 更新时间
/// </summary>
public DateTime? UpdatedTime { get; set; } = DateTime.Now;
/// <summary>
/// 更新人
/// </summary>
[MaxLength(50)]
public string? UpdatedBy { get; set; } = default!;
/// <summary>
/// 是否删除标识0false 1true
/// </summary>
public bool IsDeleted { get; set; }
}
/// <summary>
/// EntityBase
/// </summary>
/// <typeparam name="TPrimaryKey"></typeparam>
public abstract class EntityBase<TPrimaryKey>
{
/// <summary>
/// Id
/// </summary>
public virtual TPrimaryKey Id { get; set; }
}
#region 生成Id
/// <summary>
/// 生成Id
/// </summary>
/// <param name="size"></param>
/// <returns></returns>
private string GetId(string size = "32")
{
if (size?.Equals("16") ?? false)
{
long i = 1;
foreach (byte b in Guid.NewGuid().ToByteArray())
{
i *= b + 1;
}
return string.Format("{0:x}", i - DateTime.Now.Ticks);
}
else if (size?.Equals("32") ?? false)
{
return Guid.NewGuid().ToString("N");
}
throw new NotSupportedException($"{size} 暂不支持!");
}
#endregion
}
- 实际使用时候在Service服务中添加类似如下
public class TestService : ITestService
{
private readonly IMySqlDbRepository<MySqlSjDbContext> _uoRepository;
public TestService(IMySqlDbRepository<MySqlWebApiDbContext>)
{
_uoRepository = uoRepository;
}
public string AddUserInfo()
{
try
{
var transaction = _uoRepository.BeginTransaction();
var userList = _uoRepository.Get<UserEntity>(a => a.LoginName == "aa").ToList();
if (userList.Count == 0)
{
_uoRepository.Insert(new UserEntity());
_uoRepository.Insert(new UserEntity());
result = 1;
}
else
{
_uoRepository.Rollback();
return "用户已存在!";
}
_uoRepository.Commit();
}
catch (Exception e)
{
_uoRepository.Rollback();
}
return "";
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- AdoNetCore.AseClient (>= 0.19.2)
- Dapper (>= 2.1.35)
- Dapper.Contrib (>= 2.0.78)
- Microsoft.EntityFrameworkCore (>= 8.0.7)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.7)
- Newtonsoft.Json (>= 13.0.3)
- NSubstitute (>= 5.0.0)
- Pomelo.EntityFrameworkCore.MySql (>= 8.0.2)
- System.Data.SqlClient (>= 4.8.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.