??? CoreShop源程序是以數(shù)據(jù)庫優(yōu)先進(jìn)行定義的,所以其本身不包含代碼優(yōu)先的定義,但本從更習(xí)慣于代碼優(yōu)先,所以為其定義了代碼優(yōu)先的定義。
1 CoreCms.Net.Model.Entities.SysRole
using SqlSugar;
using System.ComponentModel.DataAnnotations;
namespace CoreCms.Net.Model.Entities
{
? ? /// <summary>
? ? /// 【系統(tǒng)角色--類】
? ? /// <remarks>
? ? /// 摘要:
? ? /// ? ? 通過該實體類及其屬性成員,用于實現(xiàn)當(dāng)前程序【CoreCms.Net.Model】.【實體集】.【SysRole】實體與“[CoreShop230628].[SysRole]”表之間的CURD的交互操作,并把這些數(shù)據(jù)存儲到數(shù)據(jù)庫設(shè)置實例中(內(nèi)存)。
? ? /// </remarks>
? ? /// </summary>
? ? [SugarTable("SysRole", TableDescription = "角色表")]
? ? public class SysRole
? ? {
? ? ? ? /// <summary>
? ? ? ? /// 【角色編號】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置系統(tǒng)角色實體1個指定實例的整型編號值。
? ? ? ? /// IsPrimaryKey:主鍵
? ? ? ? /// IsIdentit:自增
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "角色編號")]
? ? ? ? [SugarColumn(ColumnDescription = "角色編號", IsPrimaryKey = true, IsIdentity = true)]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public int Id { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【角色名稱】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)角色的名稱。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "角色名稱")]
? ? ? ? [SugarColumn(ColumnDescription = "角色名稱", ColumnDataType = "nvarchar", Length = 50)]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string RoleName { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【角色名稱】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)角色的標(biāo)識。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "角色標(biāo)識")]
? ? ? ? [SugarColumn(ColumnDescription = "角色標(biāo)識", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string RoleCode { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【角色名稱】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)角色的備注。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "備注")]
? ? ? ? [SugarColumn(ColumnDescription = "備注", ?ColumnDataType = "nvarchar", Length = 255, IsNullable = true)]
? ? ? ? [StringLength(255, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string Comments { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【邏輯刪除?】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個值false(可用=0)/true(已經(jīng)被邏輯刪除=1),該值指示系統(tǒng)角色實體的1個指定實例是否已經(jīng)處于邏輯刪除狀態(tài)。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "是否刪除,0否,1是")]
? ? ? ? [SugarColumn(ColumnDescription = "是否刪除,0否,1是")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public bool Deleted { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【創(chuàng)建時間】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置系統(tǒng)角色實體1個指定實例第1次被持久化到系統(tǒng)角色表中的時間。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "創(chuàng)建時間")]
? ? ? ? [SugarColumn(ColumnDescription = "創(chuàng)建時間")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public DateTime CreateTime { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【修改時間】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置系統(tǒng)角色1個指定實例最后1次被修改后,持久化到系統(tǒng)角色表中的時間。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "修改時間")]
? ? ? ? [SugarColumn(ColumnDescription = "修改時間")]
? ? ? ? public DateTime UpdateTime { get; set; }
? ? }
}
2 CoreCms.Net.Model.Entities.SysUser
using SqlSugar;
using System.ComponentModel.DataAnnotations;
namespace CoreCms.Net.Model.Entities
{
? ? /// <summary>
? ? /// 【系統(tǒng)用戶--類】
? ? /// <remarks>
? ? /// 摘要:
? ? /// ? ? 通過該實體類及其屬性成員,用于實現(xiàn)當(dāng)前程序【CoreCms.Net.Model】.【實體集】.【SysUser】實體與“[CoreShop230628].[SysUser]”表之間的CURD的交互操作,并把這些數(shù)據(jù)存儲到數(shù)據(jù)庫設(shè)置實例中(內(nèi)存)。
? ? /// </remarks>
? ? /// </summary>
? ? [SugarTable("SysUser", TableDescription = "用戶表")]
? ? public partial class SysUser
? ? {
? ? ? ? /// <summary>
? ? ? ? /// 【系統(tǒng)用戶色編號】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置系統(tǒng)角色實體1個指定實例的整型編號值。
? ? ? ? /// IsPrimaryKey:主鍵
? ? ? ? /// IsIdentit:自增
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "用戶id")]
? ? ? ? [SugarColumn(ColumnDescription = "用戶id", IsPrimaryKey = true, IsIdentity = true)]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public int Id { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【賬號】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的賬號名稱。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "賬號")]
? ? ? ? [SugarColumn(ColumnDescription = "賬號", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string UserName { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【密碼】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的登錄密碼。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "密碼")]
? ? ? ? [SugarColumn(ColumnDescription = "密碼", ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
? ? ? ? [StringLength(100, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string PassWord { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【昵稱】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的昵稱。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "昵稱")]
? ? ? ? [SugarColumn(ColumnDescription = "昵稱", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string NickName { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【昵稱】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的頭像。
? ? ? ? /// 說明:
? ? ? ? /// ? ? 該屬性通過網(wǎng)絡(luò)格式的絕/相對路徑來映射用戶頭像圖片。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "頭像")]
? ? ? ? [SugarColumn(ColumnDescription = "頭像", ColumnDataType = "nvarchar", Length = 255, IsNullable = true)]
? ? ? ? [StringLength(255, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string Avatar { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【性別】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的性別。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "性別")]
? ? ? ? [SugarColumn(ColumnDescription = "性別")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public int Sex { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【手機(jī)號】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的手機(jī)號。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "手機(jī)號")]
? ? ? ? [SugarColumn(ColumnDescription = "手機(jī)號", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string Phone { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【郵箱】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的郵箱。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "郵箱")]
? ? ? ? [SugarColumn(ColumnDescription = "郵箱", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string Email { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【郵箱驗證?】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個值false(不需要)/true(需要),該值指示1個指定系統(tǒng)用戶是否需要在郵箱驗證操作后才能執(zhí)行登錄操作。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "郵箱是否驗證")]
? ? ? ? [SugarColumn(ColumnDescription = "郵箱是否驗證")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public bool EmailVerified { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【實名】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的實名。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "真實姓名")]
? ? ? ? [SugarColumn(ColumnDescription = "真實姓名", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string TrueName { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【身份證號】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的身份證號。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "身份證號")]
? ? ? ? [SugarColumn(ColumnDescription = "身份證號", ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
? ? ? ? [StringLength(50, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string IdCard { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【出生日期】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的生日。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "出生日期")]
? ? ? ? [SugarColumn(ColumnDescription = "出生日期", IsNullable = true)]
? ? ? ? public DateTime? Birthday { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【個人簡介】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的個人簡介。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "個人簡介")]
? ? ? ? [SugarColumn(ColumnDescription = "個人簡介", ColumnDataType = "nvarchar", Length = 500, IsNullable = true)]
? ? ? ? [StringLength(500, ErrorMessage = "【{0}】不能超過{1}字符長度")]
? ? ? ? public string Introduction { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【機(jī)構(gòu)編號】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個指定系統(tǒng)用戶的機(jī)構(gòu)編號。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "機(jī)構(gòu)id")]
? ? ? ? [SugarColumn(ColumnDescription = "機(jī)構(gòu)id", IsNullable = true)]
? ? ? ? public int? OrganizationId { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【狀態(tài)】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個值0(正常)/1 (凍結(jié)),該值指示1個指定系統(tǒng)用戶是否需要在郵箱驗證操作后才能執(zhí)行登錄操作。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "狀態(tài),0正常,1凍結(jié)")]
? ? ? ? [SugarColumn(ColumnDescription = "狀態(tài),0正常,1凍結(jié)")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public int State { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【邏輯刪除?】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置1個值false(可用=0)/true(已經(jīng)被邏輯刪除=1),該值指示系統(tǒng)用戶實體的1個指定實例是否已經(jīng)處于邏輯刪除狀態(tài)。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "是否刪除,0否,1是")]
? ? ? ? [SugarColumn(ColumnDescription = "是否刪除,0否,1是")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public bool Deleted { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【注冊時間】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置系統(tǒng)用戶實體1個指定實例第1次被持久化到系統(tǒng)用戶表中的時間。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "注冊時間")]
? ? ? ? [SugarColumn(ColumnDescription = "注冊時間")]
? ? ? ? [Required(ErrorMessage = "請輸入{0}")]
? ? ? ? public DateTime CreateTime { get; set; }
? ? ? ? /// <summary>
? ? ? ? /// 【修改時間】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 獲取/設(shè)置系統(tǒng)用戶1個指定實例最后1次被修改后,持久化到系統(tǒng)角色表中的時間。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? [Display(Name = "修改時間")]
? ? ? ? [SugarColumn(ColumnDescription = "修改時間", IsNullable = true)]
? ? ? ? public DateTime UpdateTime { get; set; }
? ? }
}
3 CoreCms.Net.Core.Config.SqlSugarSetup
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using SqlSugar.IOC; ? ? ? ? ? ? ? ? ?
using System.Reflection;
namespace CoreCms.Net.Core.Config
{
? ? /// <summary>
? ? /// 【SqlSugarCore中間件啟動--類】
? ? /// <remarks>
? ? /// 摘要:
? ? /// ? ? 通過該類中的方法成員,把SqlSugarCore中間件依賴注入到.Net(Core)框架內(nèi)置依賴注入容器中。
? ? /// </remarks>
? ? /// </summary>
? ? public static class SqlSugarSetup
? ? {
? ? ? ? /// <param name="services">.Net(Core)框架內(nèi)置依賴注入容器實例。</param>
? ? ? ? /// <summary>
? ? ? ? /// 【配置服務(wù)】
? ? ? ? /// <remarks>
? ? ? ? /// 摘要:
? ? ? ? /// ? ? 通過該方法成員,把SqlSugarCore中間件依賴注入到.Net(Core)框架內(nèi)置依賴注入容器中。。
? ? ? ? /// </remarks>
? ? ? ? /// </summary>
? ? ? ? public static void AddSqlSugarSetup(this IServiceCollection services)
? ? ? ? {
? ? ? ? ? ? if (services == null) throw new ArgumentNullException(nameof(services));
? ? ? ? ? ? //注入 ORM
? ? ? ? ? ? SugarIocServices.AddSqlSugar(new IocConfig()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //數(shù)據(jù)庫連接
? ? ? ? ? ? ? ? /*ConnectionString = AppSettingsConstVars.DbSqlConnection,
? ? ? ? ? ? ? ? //判斷數(shù)據(jù)庫類型
? ? ? ? ? ? ? ? DbType = AppSettingsConstVars.DbDbType == IocDbType.MySql.ToString() ? IocDbType.MySql : IocDbType.SqlServer,*/
? ? ? ? ? ? ? ? ConnectionString = "Server=.;uid=zz;pwd=zz;Database=CoreShop230628;MultipleActiveResultSets=true;pooling=true;min pool size=5;max pool size=32767;connect timeout=20;Encrypt=True;TrustServerCertificate=True;",
? ? ? ? ? ? ? ? DbType = IocDbType.SqlServer,
? ? ? ? ? ? ? ? //是否開啟自動關(guān)閉數(shù)據(jù)庫連接-//不設(shè)成true要手動close
? ? ? ? ? ? ? ? IsAutoCloseConnection = true,
? ? ? ? ? ? });
? ? ? ? ? ? //設(shè)置參數(shù)
? ? ? ? ? ? services.ConfigurationSugar(db =>
? ? ? ? ? ? {
? ? ? ? ? ? ? ? db.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute;
? ? ? ? ? ? ? ? //說明:CoreShop的程序是數(shù)據(jù)庫優(yōu)先,即必須先生成指定的數(shù)據(jù)庫,本人更為喜歡代碼優(yōu)先所以進(jìn)行了以下定義來實現(xiàn)代碼優(yōu)先。
? ? ? ? ? ? ? ? //如果指定的數(shù)據(jù)庫軟件中不存在指定的數(shù)據(jù)庫,則自動生成該數(shù)據(jù)庫。
? ? ? ? ? ? ? ? db.DbMaintenance.CreateDatabase();
? ? ? ? ? ? ? ? //通過反射操作,獲取領(lǐng)域文件夾中的所有實體的類型實例。
? ? ? ? ? ? ? ? //直接獲取指定項目中所有類的類型實例。
? ? ? ? ? ? ? ? Assembly assembly = Assembly.Load("CoreCms.Net.Model");
? ? ? ? ? ? ? ? //通過過濾操作,獲取領(lǐng)域文件夾中的所有實體的類型實例。
? ? ? ? ? ? ? ? //注意:“Where”過濾操作中“ c.Namespace”最好使用“Contains”,而不要使用“==”。
? ? ? ? ? ? ? ? Type[] _typeArray = assembly.GetTypes()
? ? ? ? ? ? ? ? ? ? .Where(c => c.Namespace.Contains("CoreCms.Net.Model.Entities") && c.IsClass)//過濾操作。
? ? ? ? ? ? ? ? ? ? .ToArray();
? ? ? ? ? ? ? ? //如果數(shù)據(jù)庫軟件對自動生成的數(shù)據(jù)庫支持自動備份操作,則通過下行語句在自動生成該數(shù)據(jù)庫中,根據(jù)當(dāng)前項目中的實體類自動生成相應(yīng)的表。
? ? ? ? ? ? ? ? //注意:SetStringDefaultLength(stringDefaultLength)必須定義在下行語句中,否則在自動生成表時,該約束定義將不會被映射到表的字段上。
? ? ? ? ? ? ? ? db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(_typeArray);
? ? ? ? ? ? });
? ? ? ? }
? ? }
}
4 Program.cs
using CoreCms.Net.Core.Config;
var builder = WebApplication.CreateBuilder(args);
//添加數(shù)據(jù)庫連接SqlSugar注入支持
builder.Services.AddSqlSugarSetup();
5 CoreCms.Net.Web.Admin.Controllers.SysRoleController
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
using SqlSugar;
using SqlSugar.IOC;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Web.Admin.Controllers
{
? ? [ApiController]
? ? [Route("[controller]/[action]")]
? ? public class SysRoleController : ControllerBase
? ? {
? ? ? private readonly ISqlSugarClient _sqlSugarClient;
? ? ? ? private ISqlSugarClient DbBaseClient;
? ? ? ? public SysRoleController()
? ? ? ? {
? ? ? ? ? ? _sqlSugarClient = DbScoped.SugarScope;
? ? ? ? }
? ? ? ? private SqlSugarScope GetDbClient()
? ? ? ? {
? ? ? ? ? ? // 必須要as,后邊會用到切換數(shù)據(jù)庫操作
? ? ? ? ? ? return _sqlSugarClient as SqlSugarScope;
? ? ? ? }
? ? ? ? #region 獲取列表============================================================
? ? ? ? [HttpPost]
? ? ? ? [Description("獲取列表")]
? ? ? ? public async Task</*AdminUiCallBack*/ bool> GetPageList()
? ? ? ? {
? ? ? ? ? ? DbBaseClient = GetDbClient();
? ? ? ? ? var v = await DbBaseClient
? ? ? ? ? ? ? ? .Queryable<SysRole>()
? ? ? ? ? ? ? ? .ToListAsync();
? ? ? ? ? ? return true;
? ? ? ? }
? ? ? ? #endregion
? ? }
}
?文章來源:http://www.zghlxwxcb.cn/news/detail-614334.html
對以上功能更為具體實現(xiàn)和注釋見:230725_001CoreShop230628(獲取數(shù)據(jù)庫中的數(shù)據(jù))。文章來源地址http://www.zghlxwxcb.cn/news/detail-614334.html
到了這里,關(guān)于第1章 獲取數(shù)據(jù)庫中的數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!