mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 增加 实体备注从 Description/Display/DisplayName 等特性兼容读取;
This commit is contained in:
parent
7c12b546b3
commit
4a4751708a
@ -569,6 +569,8 @@ namespace base_entity
|
||||
#endregion
|
||||
fsql.UseJsonMap();
|
||||
|
||||
var displayNameTb = fsql.CodeFirst.GetTableByEntity(typeof(DeviceCodes));
|
||||
|
||||
var joinsql1 = fsql.Select<JoinTest01>()
|
||||
.Include(a => a.Parent.Parent)
|
||||
.Where(a => a.Parent.Parent.code == "001")
|
||||
|
@ -733,15 +733,6 @@
|
||||
<param name="modelBuilder"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlDbContextExtensions.ApplyConfigurationsFromAssembly(FreeSql.ICodeFirst,System.Reflection.Assembly,System.Func{System.Type,System.Boolean})">
|
||||
<summary>
|
||||
根据Assembly扫描所有继承IEntityTypeConfiguration<T>的配置类
|
||||
</summary>
|
||||
<param name="codeFirst"></param>
|
||||
<param name="assembly"></param>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlDbContextExtensions.CreateDbContext(IFreeSql)">
|
||||
<summary>
|
||||
创建普通数据上下文档对象
|
||||
@ -800,14 +791,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -1,6 +1,5 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.DatabaseModel;
|
||||
using FreeSql.Extensions.EntityUtil;
|
||||
using FreeSql.Internal.Model;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
@ -10,7 +9,6 @@ using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -607,6 +605,21 @@ namespace FreeSql.Internal
|
||||
|
||||
return dic;
|
||||
|
||||
string GetByAttribute(object[] attrs, string attributeName)
|
||||
{
|
||||
var dyattr = attrs?.Where(a => {
|
||||
return ((a as Attribute)?.TypeId as Type)?.Name == attributeName;
|
||||
}).FirstOrDefault();
|
||||
if (dyattr == null) return null;
|
||||
var dyattrProps = dyattr.GetType().GetProperties();
|
||||
return dyattrProps.Where(a => a.PropertyType == typeof(string) && a.Name == "Description").FirstOrDefault()?.GetValue(dyattr, null)?.ToString() ??
|
||||
dyattrProps.Where(a => a.PropertyType == typeof(string) && a.Name == "Name").FirstOrDefault()?.GetValue(dyattr, null)?.ToString() ??
|
||||
dyattrProps.Where(a => a.PropertyType == typeof(string) && a.Name == "ShortName").FirstOrDefault()?.GetValue(dyattr, null)?.ToString() ??
|
||||
dyattrProps.Where(a => a.PropertyType == typeof(string))
|
||||
.Select(a => a?.GetValue(dyattr, null)?.ToString())
|
||||
.Where(a => !string.IsNullOrWhiteSpace(a))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
void GetDydesc(PropertyInfo prop)
|
||||
{
|
||||
object[] attrs = null;
|
||||
@ -617,19 +630,12 @@ namespace FreeSql.Internal
|
||||
prop.GetCustomAttributes(false).ToArray(); //.net core 反射存在版本冲突问题,导致该方法异常
|
||||
}
|
||||
catch { }
|
||||
|
||||
var dyattr = attrs?.Where(a => {
|
||||
return ((a as Attribute)?.TypeId as Type)?.Name == "DescriptionAttribute";
|
||||
}).FirstOrDefault();
|
||||
if (dyattr != null)
|
||||
{
|
||||
var valueProp = dyattr.GetType().GetProperties().Where(a => a.PropertyType == typeof(string)).FirstOrDefault();
|
||||
var comment = valueProp?.GetValue(dyattr, null)?.ToString();
|
||||
var comment = GetByAttribute(attrs, "DescriptionAttribute");
|
||||
if (string.IsNullOrEmpty(comment)) comment = GetByAttribute(attrs, "DisplayNameAttribute");
|
||||
if (string.IsNullOrEmpty(comment)) comment = GetByAttribute(attrs, "DisplayAttribute");
|
||||
if (string.IsNullOrEmpty(comment)) comment = GetByAttribute(attrs, "DisplayColumnAttribute");
|
||||
if (string.IsNullOrEmpty(comment) == false)
|
||||
dic.Add(prop == null ?
|
||||
"" :
|
||||
prop.Name, comment);
|
||||
}
|
||||
dic.Add(prop == null ? "" : prop.Name, comment);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user