diff --git a/FreeSql.Tests/FreeSql.Tests/DataAnnotations/EFCoreAttributeTest.cs b/FreeSql.Tests/FreeSql.Tests/DataAnnotations/EFCoreAttributeTest.cs index f3dd26ae..b3868ad2 100644 --- a/FreeSql.Tests/FreeSql.Tests/DataAnnotations/EFCoreAttributeTest.cs +++ b/FreeSql.Tests/FreeSql.Tests/DataAnnotations/EFCoreAttributeTest.cs @@ -33,12 +33,15 @@ namespace FreeSql.Tests.DataAnnotations { fsql.CodeFirst.SyncStructure(); Assert.Equal("NVARCHAR(100)", fsql.CodeFirst.GetTableByEntity(typeof(eftesttb03)).ColumnsByCs["title"].Attribute.DbType); + Assert.Equal("NVARCHAR(101)", fsql.CodeFirst.GetTableByEntity(typeof(eftesttb03)).ColumnsByCs["title2"].Attribute.DbType); } class eftesttb03 { public Guid id { get; set; } [System.ComponentModel.DataAnnotations.MaxLength(100)] public string title { get; set; } + [System.ComponentModel.DataAnnotations.StringLength(101)] + public string title2 { get; set; } } [Fact] diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index c4545e99..e0ffd602 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -2511,6 +2511,137 @@ + + + 查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】 + + + + + + + + + 查询,ExecuteReaderAsync(dr => {}, "select * from user where age > ?age", new { age = 25 }) + + + + + + + 查询 + + + + + + + 查询,ExecuteArrayAsync("select * from user where age > ?age", new { age = 25 }) + + + + + + + + 查询 + + + + + + + 查询,ExecuteDataSetAsync("select * from user where age > ?age; select 2", new { age = 25 }) + + + + + + + + 查询 + + + + + + + 查询,ExecuteDataTableAsync("select * from user where age > ?age", new { age = 25 }) + + + + + + + + 在【主库】执行 + + + + + + + + 在【主库】执行,ExecuteNonQueryAsync("delete from user where age > ?age", new { age = 25 }) + + + + + + + + 在【主库】执行 + + + + + + + + 在【主库】执行,ExecuteScalarAsync("select 1 from user where age > ?age", new { age = 25 }) + + + + + + + + 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new SqlParameter { ParameterName = "age", Value = 25 }) + + + + + + + + + + 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new { age = 25 }) + + + + + + + + + 执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 }) + + + + + + + + + + 执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new { age = 25 }) + + + + + + 可自定义解析表达式 @@ -3160,6 +3291,12 @@ 超时 + + + 获取资源 + + + 使用完毕后,归还资源 @@ -3230,6 +3367,12 @@ 资源对象 + + + 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象 + + 资源对象 + 归还对象给对象池的时候触发 diff --git a/FreeSql/FreeSqlBuilder.cs b/FreeSql/FreeSqlBuilder.cs index adb6298b..5f7b6056 100644 --- a/FreeSql/FreeSqlBuilder.cs +++ b/FreeSql/FreeSqlBuilder.cs @@ -326,6 +326,20 @@ namespace FreeSql } } + dyattr = attrs?.Where(a => { + return ((a as Attribute)?.TypeId as Type)?.Name == "StringLengthAttribute"; + }).FirstOrDefault(); + if (dyattr != null) + { + var lenProps = dyattr.GetType().GetProperties().Where(a => a.PropertyType.IsNumberType()).ToArray(); + var lenProp = lenProps.Length == 1 ? lenProps.FirstOrDefault() : lenProps.Where(a => a.Name == "MaximumLength").FirstOrDefault(); + if (lenProp != null && int.TryParse(string.Concat(lenProp.GetValue(dyattr, null)), out var tryval) && tryval != 0) + { + e.ModifyResult.StringLength = tryval; + } + } + + dyattr = attrs?.Where(a => { return ((a as Attribute)?.TypeId as Type)?.FullName == "System.ComponentModel.DataAnnotations.RequiredAttribute"; }).FirstOrDefault();