From f0b7e5e7cbdf5298f0ffad890c55a4284667968d Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Thu, 30 Mar 2023 13:27:51 +0800
Subject: [PATCH] Synchronization code
---
.../EntityMaintenance/EntityMaintenance.cs | 87 +++++++++++--------
.../SqlSugar/Utilities/UtilMethods.cs | 6 ++
2 files changed, 55 insertions(+), 38 deletions(-)
diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
index 8116f7b61..27ad9e962 100644
--- a/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
+++ b/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs
@@ -151,47 +151,58 @@ namespace SqlSugar
/// the text contents of this XML element node
public string GetXElementNodeValue(Type entityType, string nodeAttributeName)
{
- if (this.Context.CurrentConnectionConfig?.MoreSettings?.IsNoReadXmlDescription == true)
- {
- return "";
- }
- if (entityType.Assembly.IsDynamic&& entityType.Assembly.FullName.StartsWith("Dynamic"))
- {
- return null;
- }
- var path = entityType.Assembly.Location;
- if (string.IsNullOrEmpty(path))
- {
- return null;
- }
- FileInfo file = new FileInfo(path);
- string xmlPath = entityType.Assembly.Location.Replace(file.Extension, ".xml");
- if (!File.Exists(xmlPath))
- {
- return string.Empty;
- }
- XElement xe =new ReflectionInoCacheService().GetOrCreate("EntityXml_"+xmlPath,()=> XElement.Load(xmlPath));
- if (xe == null)
- {
- return string.Empty;
- }
- var xeNode = xe.Element("members").Elements("member").Where(ele => ele.Attribute("name").Value == nodeAttributeName).FirstOrDefault();
- if (xeNode == null)
- {
- return string.Empty;
- }
- var summary = xeNode.Element("summary");
- if (summary != null)
+
+ try
{
- return summary.Value.ToSqlFilter().Trim();
+
+ if (this.Context.CurrentConnectionConfig?.MoreSettings?.IsNoReadXmlDescription == true)
+ {
+ return "";
+ }
+ if (entityType.Assembly.IsDynamic&& entityType.Assembly.FullName.StartsWith("Dynamic"))
+ {
+ return null;
+ }
+ var path = entityType.Assembly.Location;
+ if (string.IsNullOrEmpty(path))
+ {
+ return null;
+ }
+ FileInfo file = new FileInfo(path);
+ string xmlPath = entityType.Assembly.Location.Replace(file.Extension, ".xml");
+ if (!File.Exists(xmlPath))
+ {
+ return string.Empty;
+ }
+ XElement xe =new ReflectionInoCacheService().GetOrCreate("EntityXml_"+xmlPath,()=> XElement.Load(xmlPath));
+ if (xe == null)
+ {
+ return string.Empty;
+ }
+ var xeNode = xe.Element("members").Elements("member").Where(ele => ele.Attribute("name").Value == nodeAttributeName).FirstOrDefault();
+ if (xeNode == null)
+ {
+ return string.Empty;
+ }
+ var summary = xeNode.Element("summary");
+ if (summary != null)
+ {
+ return summary.Value.ToSqlFilter().Trim();
+ }
+ else
+ {
+ var summaryValue = xeNode.Elements().Where(x => x.Name.ToString().EqualCase("summary")).Select(it => it.Value).FirstOrDefault();
+ if(summaryValue==null)
+ return string.Empty;
+ else
+ return summaryValue.ToSqlFilter().Trim()??"";
+ }
+
}
- else
+ catch
{
- var summaryValue = xeNode.Elements().Where(x => x.Name.ToString().EqualCase("summary")).Select(it => it.Value).FirstOrDefault();
- if(summaryValue==null)
- return string.Empty;
- else
- return summaryValue.ToSqlFilter().Trim()??"";
+ Check.ExceptionEasy("ORM error reading entity class XML, check entity XML or disable reading XML: MoreSettings IsNoReadXmlDescription set to true (same place to set DbType)", "ORM读取实体类的XML出现错误,检查实体XML或者禁用读取XML: MoreSettings里面的IsNoReadXmlDescription设为true (设置DbType的同一个地方)");
+ throw;
}
}
///
diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs
index 134183dbf..16dafd157 100644
--- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs
+++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs
@@ -17,6 +17,12 @@ namespace SqlSugar
{
public class UtilMethods
{
+ public static string GetNativeSql(string sql,SugarParameter[] pars)
+ {
+ if (pars == null||pars.Length==0)
+ return "\r\n[Sql]:"+sql+"\r\n";
+ return $"\r\n[Sql]:{sql} \r\n[Pars]:{string.Join(" ",pars.Select(it=>$"\r\n[Name]:{it.ParameterName} [Value]:{it.Value} [Type]:{it.DbType} "))} \r\n";
+ }
public static string ToUnderLine(string str, bool isToUpper = false)
{
if (str == null || str.Contains("_"))