Xiezn.Core/Business/DB/DbContext.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xiezn.Core.Common.Helpers;
using Xiezn.Core.Models.ConfModel;

namespace Xiezn.Core.Business.DB
{
    public class DbContext<T> where T : class, new()
    {
        public DbContext()
        {
            DbConfig dbConfig = ConfigHelper.GetConfig<DbConfig>("DbConfig");

            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = dbConfig.ConnectionString,
                DbType = dbConfig.DbType.ToLower() == "mysql" ? DbType.MySql : DbType.SqlServer,
                InitKeyType = InitKeyType.Attribute,
                IsAutoCloseConnection = true,

            });

            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                // Console.WriteLine(sql + "\r\n" +
                    // Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                // Console.WriteLine();
            };
        }

        public SqlSugarClient Db;
        public SimpleClient<T> CurrentDb { get { return new SimpleClient<T>(Db); } }

        public dynamic Common(string tableName, string columnName, string columnValue = "", int type = 0, string sign = "option", int remindStart = 0, int remindEnd = 0)
        {
            sign = sign.ToLower();
            string sql = "";
            dynamic res = null;
            switch (sign)
            {
                case "option":
                    string where = "";
                    if (type == 1)
                    {
                        where = " WHERE level = " + type;
                    }

                    if (type > 1)
                    {
                        where = " WHERE level = " + type + " AND parent = " + columnValue;
                    }
                    sql = "SELECT " + columnName + " FROM " + tableName + where;
                    res = Db.Ado.SqlQuery<string>(sql).ToList();
                    break;

                case "follow":
                    sql = "SELECT * FROM " + tableName +" WHERE " + columnName + " = '" + columnValue + "'";
后面还有 78 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。