瀏覽代碼

解决dbcontext的一个bug

shengxuefei 4 年之前
父節點
當前提交
342d22c686

+ 4 - 6
PMS.NetCore/PMS.NetCore.BusinessCore/DbCore/DbContext.cs

@@ -17,7 +17,7 @@ public class DbContext<T> where T : class, new()
             IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样我就不多解释了
 
         });
-        //调式代码 用来打印SQL 
+        //调式代码 用来打印SQL
         Db.Aop.OnLogExecuting = (sql, pars) =>
         {
             Console.WriteLine(sql + "\r\n" +
@@ -28,7 +28,7 @@ public class DbContext<T> where T : class, new()
     }
     //注意:不能写成静态的
     public SqlSugarClient Db;//用来处理事务多表查询和复杂的操作
-	public SimpleClient<T> CurrentDb { get { return Db.GetSimpleClient<T>(); } }//用来操作当前表的数据
+    public SimpleClient<T> CurrentDb { get { return Db.GetSimpleClient<T>(); } }//用来操作当前表的数据
 
    public SimpleClient<fdc_pm_occupation> fdc_pm_occupationDb { get { return Db.GetSimpleClient<fdc_pm_occupation>(); } }//用来处理fdc_pm_occupation表的常用操作
    public SimpleClient<fdc_pmzsystemUser> fdc_pmzsystemUserDb { get { return Db.GetSimpleClient<fdc_pmzsystemUser>(); } }//用来处理fdc_pmzsystemUser表的常用操作
@@ -257,7 +257,7 @@ public class DbContext<T> where T : class, new()
     /// 根据主键查询
     /// </summary>
     /// <returns></returns>
-    public virtual List<T> GetById(dynamic id)
+    public virtual T GetById(dynamic id)
     {
         return CurrentDb.GetById(id);
     }
@@ -346,7 +346,5 @@ public class DbContext<T> where T : class, new()
     }
 
 
-    //自已扩展更多方法 
+    //自已扩展更多方法
 }
-
-

+ 3 - 2
PMS.NetCore/PMS.NetCore/Controllers/OrganizationController.cs

@@ -108,19 +108,20 @@ namespace PMS.NetCore.Controllers
         [Route("CorpsUpdate")]
         public JsonResult CorpsUpdate([FromBody] corps model)
         {
+            logger.Info($"【CorpsUpdate】model:{JsonConvert.SerializeObject(model)}");
             var manger = new corpsManager();
             if (!model.pk_corp.IsInteger())
             {
                 return Json("单位编码必须是整数形式");
             }
-            var mod = manger.GetById(model.pk_corp).FirstOrDefault();
+            var mod = manger.GetById(model.pk_corp);
             if (mod == null)
             {
                 return Json("不存在的组织机构");
             }
             if (model.fathercode != "0")
             {
-                var father = manger.GetById(model.fathercode).FirstOrDefault();
+                var father = manger.GetById(model.fathercode);
                 if (father == null)
                 {
                     return Json("上级公司不存在,请重新选择");