mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	Internal optimization
This commit is contained in:
		@@ -172,6 +172,14 @@ namespace base_entity
 | 
				
			|||||||
            public CommandTimeoutCascade(int timeout) => _asyncLocalTimeout.Value = timeout;
 | 
					            public CommandTimeoutCascade(int timeout) => _asyncLocalTimeout.Value = timeout;
 | 
				
			||||||
            public void Dispose() => _asyncLocalTimeout.Value = 0;
 | 
					            public void Dispose() => _asyncLocalTimeout.Value = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        class EnterpriseInfo
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            [Column(IsPrimary = true, DbType = "varchar(60)")]
 | 
				
			||||||
 | 
					            public string id { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(DbType = "varchar(128)")]
 | 
				
			||||||
 | 
					            public string img { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        static void Main(string[] args)
 | 
					        static void Main(string[] args)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            #region 初始化 IFreeSql
 | 
					            #region 初始化 IFreeSql
 | 
				
			||||||
@@ -217,6 +225,8 @@ namespace base_entity
 | 
				
			|||||||
            BaseEntity.Initialization(fsql, () => _asyncUow.Value);
 | 
					            BaseEntity.Initialization(fsql, () => _asyncUow.Value);
 | 
				
			||||||
            #endregion
 | 
					            #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var sql122234 = fsql.CodeFirst.GetComparisonDDLStatements<EnterpriseInfo>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (fsql.Ado.DataType == DataType.PostgreSQL)
 | 
					            if (fsql.Ado.DataType == DataType.PostgreSQL)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                fsql.CodeFirst.IsNoneCommandParameter = false;
 | 
					                fsql.CodeFirst.IsNoneCommandParameter = false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,11 +3,23 @@ using System.Linq;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace FreeSql.DataAnnotations
 | 
					namespace FreeSql.DataAnnotations
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
 | 
				
			||||||
 | 
					    /// ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id<para></para>
 | 
				
			||||||
 | 
					    /// _________________public Category Category { get; set; }<para></para>
 | 
				
			||||||
 | 
					    /// OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))]<para></para>
 | 
				
			||||||
 | 
					    /// _________________public List<Topic> Topics { get; set; }<para></para>
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
    public class NavigateAttribute : Attribute
 | 
					    public class NavigateAttribute : Attribute
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 手工绑定 OneToMany、ManyToOne 导航关系
 | 
					        /// OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
 | 
				
			||||||
 | 
					        /// ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id<para></para>
 | 
				
			||||||
 | 
					        /// _________________public Category Category { get; set; }<para></para>
 | 
				
			||||||
 | 
					        /// OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))]<para></para>
 | 
				
			||||||
 | 
					        /// _________________public List<Topic> Topics { get; set; }<para></para>
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public string Bind { get; set; }
 | 
					        public string Bind { get; set; }
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@@ -15,6 +27,13 @@ namespace FreeSql.DataAnnotations
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public Type ManyToMany { get; set; }
 | 
					        public Type ManyToMany { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
 | 
				
			||||||
 | 
					        /// ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id<para></para>
 | 
				
			||||||
 | 
					        /// _________________public Category Category { get; set; }<para></para>
 | 
				
			||||||
 | 
					        /// OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))]<para></para>
 | 
				
			||||||
 | 
					        /// _________________public List<Topic> Topics { get; set; }<para></para>
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
        public NavigateAttribute(string bind)
 | 
					        public NavigateAttribute(string bind)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.Bind = bind;
 | 
					            this.Bind = bind;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -367,9 +367,22 @@
 | 
				
			|||||||
            是否唯一
 | 
					            是否唯一
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="T:FreeSql.DataAnnotations.NavigateAttribute">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
 | 
				
			||||||
 | 
					            ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id<para></para>
 | 
				
			||||||
 | 
					            _________________public Category Category { get; set; }<para></para>
 | 
				
			||||||
 | 
					            OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))]<para></para>
 | 
				
			||||||
 | 
					            _________________public List<Topic> Topics { get; set; }<para></para>
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
        <member name="P:FreeSql.DataAnnotations.NavigateAttribute.Bind">
 | 
					        <member name="P:FreeSql.DataAnnotations.NavigateAttribute.Bind">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            手工绑定 OneToMany、ManyToOne 导航关系
 | 
					            OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
 | 
				
			||||||
 | 
					            ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id<para></para>
 | 
				
			||||||
 | 
					            _________________public Category Category { get; set; }<para></para>
 | 
				
			||||||
 | 
					            OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))]<para></para>
 | 
				
			||||||
 | 
					            _________________public List<Topic> Topics { get; set; }<para></para>
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="P:FreeSql.DataAnnotations.NavigateAttribute.ManyToMany">
 | 
					        <member name="P:FreeSql.DataAnnotations.NavigateAttribute.ManyToMany">
 | 
				
			||||||
@@ -377,6 +390,15 @@
 | 
				
			|||||||
            手工绑定 ManyToMany 导航关系
 | 
					            手工绑定 ManyToMany 导航关系
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:FreeSql.DataAnnotations.NavigateAttribute.#ctor(System.String)">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary<para></para>
 | 
				
			||||||
 | 
					            ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id<para></para>
 | 
				
			||||||
 | 
					            _________________public Category Category { get; set; }<para></para>
 | 
				
			||||||
 | 
					            OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))]<para></para>
 | 
				
			||||||
 | 
					            _________________public List<Topic> Topics { get; set; }<para></para>
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
        <member name="P:FreeSql.DataAnnotations.OraclePrimaryKeyNameAttribute.Name">
 | 
					        <member name="P:FreeSql.DataAnnotations.OraclePrimaryKeyNameAttribute.Name">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            主键名
 | 
					            主键名
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -151,6 +151,11 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                var firstTb = _tables[0];
 | 
					                var firstTb = _tables[0];
 | 
				
			||||||
                var firstTbs = _tables.Where(a => a.AliasInit == field[0]).ToArray();
 | 
					                var firstTbs = _tables.Where(a => a.AliasInit == field[0]).ToArray();
 | 
				
			||||||
                if (firstTbs.Length == 1) firstTb = firstTbs[0];
 | 
					                if (firstTbs.Length == 1) firstTb = firstTbs[0];
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    firstTbs = _tables.Where(a => a.Table.Type.Name == field[0]).ToArray();
 | 
				
			||||||
 | 
					                    if (firstTbs.Length == 1) firstTb = firstTbs[0];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                firstTb.Parameter = Expression.Parameter(firstTb.Table.Type, firstTb.Alias);
 | 
					                firstTb.Parameter = Expression.Parameter(firstTb.Table.Type, firstTb.Alias);
 | 
				
			||||||
                var currentType = firstTb.Table.Type;
 | 
					                var currentType = firstTb.Table.Type;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -530,16 +530,23 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                if (col.Attribute.MapType.NullableTypeOrThis() == typeof(DateTime))
 | 
					                if (col.Attribute.MapType.NullableTypeOrThis() == typeof(DateTime))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    col.DbScale = (byte)size;
 | 
					                    col.DbScale = (byte)size;
 | 
				
			||||||
 | 
					                    if (col.Attribute.Scale <= 0) col.Attribute.Scale = col.DbScale;
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (sizeArr.Length == 1)
 | 
					                if (sizeArr.Length == 1)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    col.DbSize = size;
 | 
					                    col.DbSize = size;
 | 
				
			||||||
 | 
					                    if (col.Attribute.StringLength <= 0) col.Attribute.StringLength = col.DbSize;
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (byte.TryParse(sizeArr[1], out var scale) == false) continue;
 | 
					                if (byte.TryParse(sizeArr[1], out var scale) == false) continue;
 | 
				
			||||||
                col.DbPrecision = (byte)size;
 | 
					                col.DbPrecision = (byte)size;
 | 
				
			||||||
                col.DbScale = scale;
 | 
					                col.DbScale = scale;
 | 
				
			||||||
 | 
					                if (col.Attribute.Precision <= 0)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    col.Attribute.Precision = col.DbPrecision;
 | 
				
			||||||
 | 
					                    col.Attribute.Scale = col.DbScale;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            trytb.IsRereadSql = trytb.Columns.Where(a => string.IsNullOrWhiteSpace(a.Value.Attribute.RereadSql) == false).Any();
 | 
					            trytb.IsRereadSql = trytb.Columns.Where(a => string.IsNullOrWhiteSpace(a.Value.Attribute.RereadSql) == false).Any();
 | 
				
			||||||
            tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
 | 
					            tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user