From 71ba136e08d6a13f09a3b70ce400894ff97fe9a1 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Wed, 25 May 2022 13:46:33 +0800 Subject: [PATCH] Internal optimization --- Examples/base_entity/Program.cs | 10 ++++++++ FreeSql/DataAnnotations/NavigateAttribute.cs | 21 +++++++++++++++- FreeSql/FreeSql.xml | 24 ++++++++++++++++++- .../SelectProvider/Select0Provider.cs | 5 ++++ FreeSql/Internal/UtilsExpressionTree.cs | 7 ++++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index 35712f50..d9bbe1a7 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -172,6 +172,14 @@ namespace base_entity public CommandTimeoutCascade(int timeout) => _asyncLocalTimeout.Value = timeout; 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) { #region 初始化 IFreeSql @@ -217,6 +225,8 @@ namespace base_entity BaseEntity.Initialization(fsql, () => _asyncUow.Value); #endregion + var sql122234 = fsql.CodeFirst.GetComparisonDDLStatements(); + if (fsql.Ado.DataType == DataType.PostgreSQL) { fsql.CodeFirst.IsNoneCommandParameter = false; diff --git a/FreeSql/DataAnnotations/NavigateAttribute.cs b/FreeSql/DataAnnotations/NavigateAttribute.cs index f17b4348..f1aa3058 100644 --- a/FreeSql/DataAnnotations/NavigateAttribute.cs +++ b/FreeSql/DataAnnotations/NavigateAttribute.cs @@ -3,11 +3,23 @@ using System.Linq; namespace FreeSql.DataAnnotations { + + /// + /// OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary + /// ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id + /// _________________public Category Category { get; set; } + /// OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))] + /// _________________public List<Topic> Topics { get; set; } + /// public class NavigateAttribute : Attribute { /// - /// 手工绑定 OneToMany、ManyToOne 导航关系 + /// OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary + /// ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id + /// _________________public Category Category { get; set; } + /// OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))] + /// _________________public List<Topic> Topics { get; set; } /// public string Bind { get; set; } /// @@ -15,6 +27,13 @@ namespace FreeSql.DataAnnotations /// public Type ManyToMany { get; set; } + /// + /// OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary + /// ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id + /// _________________public Category Category { get; set; } + /// OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))] + /// _________________public List<Topic> Topics { get; set; } + /// public NavigateAttribute(string bind) { this.Bind = bind; diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 90d7f92e..d13dade8 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -367,9 +367,22 @@ 是否唯一 + + + OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary + ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id + _________________public Category Category { get; set; } + OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))] + _________________public List<Topic> Topics { get; set; } + + - 手工绑定 OneToMany、ManyToOne 导航关系 + OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary + ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id + _________________public Category Category { get; set; } + OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))] + _________________public List<Topic> Topics { get; set; } @@ -377,6 +390,15 @@ 手工绑定 ManyToMany 导航关系 + + + OneToOne:[Navigate(nameof(Primary))] <-> (缺省)外表.Primary + ManyToOne:Topic.cs 文件 [Navigate(nameof(Topic.CategoryId))] <-> (缺省)Category.Id + _________________public Category Category { get; set; } + OneToMany:Category.cs 文件 (缺省)Category.Id <-> [Navigate(nameof(Topic.CategoryId))] + _________________public List<Topic> Topics { get; set; } + + 主键名 diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs index 5b4f2268..6f7a0fea 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs @@ -151,6 +151,11 @@ namespace FreeSql.Internal.CommonProvider var firstTb = _tables[0]; var firstTbs = _tables.Where(a => a.AliasInit == field[0]).ToArray(); 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); var currentType = firstTb.Table.Type; diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index ff5fffa1..ef597d07 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -530,16 +530,23 @@ namespace FreeSql.Internal if (col.Attribute.MapType.NullableTypeOrThis() == typeof(DateTime)) { col.DbScale = (byte)size; + if (col.Attribute.Scale <= 0) col.Attribute.Scale = col.DbScale; continue; } if (sizeArr.Length == 1) { col.DbSize = size; + if (col.Attribute.StringLength <= 0) col.Attribute.StringLength = col.DbSize; continue; } if (byte.TryParse(sizeArr[1], out var scale) == false) continue; col.DbPrecision = (byte)size; 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(); tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);