mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- update internal code
This commit is contained in:
parent
3be28677d2
commit
4289d8da69
@ -135,7 +135,7 @@ namespace FreeSql
|
|||||||
}
|
}
|
||||||
if (collectionBefore != null && collectionAfter == null)
|
if (collectionBefore != null && collectionAfter == null)
|
||||||
{
|
{
|
||||||
//foreach (var item in collectionBefore as IEnumerable)
|
//foreach (var item in collectionBefore)
|
||||||
//{
|
//{
|
||||||
// changelog.DeleteLog.Add(NativeTuple.Create(elementType, new[] { item }));
|
// changelog.DeleteLog.Add(NativeTuple.Create(elementType, new[] { item }));
|
||||||
// NavigateReader(boundaryName, fsql, elementType, item, (path, tr, ct, stackvs) =>
|
// NavigateReader(boundaryName, fsql, elementType, item, (path, tr, ct, stackvs) =>
|
||||||
@ -148,12 +148,12 @@ namespace FreeSql
|
|||||||
}
|
}
|
||||||
Dictionary<string, object> dictBefore = new Dictionary<string, object>();
|
Dictionary<string, object> dictBefore = new Dictionary<string, object>();
|
||||||
Dictionary<string, object> dictAfter = new Dictionary<string, object>();
|
Dictionary<string, object> dictAfter = new Dictionary<string, object>();
|
||||||
foreach (var item in collectionBefore as IEnumerable)
|
foreach (var item in collectionBefore)
|
||||||
{
|
{
|
||||||
var key = fsql.GetEntityKeyString(elementType, item, false);
|
var key = fsql.GetEntityKeyString(elementType, item, false);
|
||||||
if (key != null) dictBefore.Add(key, item);
|
if (key != null) dictBefore.Add(key, item);
|
||||||
}
|
}
|
||||||
foreach (var item in collectionAfter as IEnumerable)
|
foreach (var item in collectionAfter)
|
||||||
{
|
{
|
||||||
var key = fsql.GetEntityKeyString(elementType, item, false);
|
var key = fsql.GetEntityKeyString(elementType, item, false);
|
||||||
if (key != null)
|
if (key != null)
|
||||||
@ -385,7 +385,7 @@ namespace FreeSql
|
|||||||
if (propvalFrom == null)
|
if (propvalFrom == null)
|
||||||
{
|
{
|
||||||
EntityUtilExtensions.SetEntityValueWithPropertyName(fsql, entityType, entityTo, prop.Name, null);
|
EntityUtilExtensions.SetEntityValueWithPropertyName(fsql, entityType, entityTo, prop.Name, null);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
switch (tbref.RefType)
|
switch (tbref.RefType)
|
||||||
{
|
{
|
||||||
|
@ -800,14 +800,5 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="../readme.md" Pack="true" PackagePath="\"/>
|
<None Include="../readme.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="../logo.png" Pack="true" PackagePath="\" />
|
<None Include="../logo.png" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1086,6 +1086,82 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder">
|
||||||
|
<summary>
|
||||||
|
动态创建实体类型
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.#ctor(IFreeSql,System.String,System.Attribute[])">
|
||||||
|
<summary>
|
||||||
|
配置Class
|
||||||
|
</summary>
|
||||||
|
<param name="className">类名</param>
|
||||||
|
<param name="attributes">类标记的特性[Table(Name = "xxx")] [Index(xxxx)]</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Attribute[])">
|
||||||
|
<summary>
|
||||||
|
配置属性
|
||||||
|
</summary>
|
||||||
|
<param name="propertyName">属性名称</param>
|
||||||
|
<param name="propertyType">属性类型</param>
|
||||||
|
<param name="attributes">属性标记的特性-支持多个</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Boolean,System.Attribute[])">
|
||||||
|
<summary>
|
||||||
|
配置属性
|
||||||
|
</summary>
|
||||||
|
<param name="propertyName">属性名称</param>
|
||||||
|
<param name="propertyType">属性类型</param>
|
||||||
|
<param name="isOverride">该属性是否重写父类属性</param>
|
||||||
|
<param name="attributes">属性标记的特性-支持多个</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Property(System.String,System.Type,System.Boolean,System.Object,System.Attribute[])">
|
||||||
|
<summary>
|
||||||
|
配置属性
|
||||||
|
</summary>
|
||||||
|
<param name="propertyName">属性名称</param>
|
||||||
|
<param name="propertyType">属性类型</param>
|
||||||
|
<param name="isOverride">该属性是否重写父类属性</param>
|
||||||
|
<param name="defaultValue">属性默认值</param>
|
||||||
|
<param name="attributes">属性标记的特性-支持多个</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Extend(System.Type)">
|
||||||
|
<summary>
|
||||||
|
配置父类
|
||||||
|
</summary>
|
||||||
|
<param name="superClass">父类类型</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.OverrideProperty(System.Reflection.Emit.TypeBuilder@,System.Reflection.Emit.MethodBuilder,FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.PropertyMethodEnum,System.String)">
|
||||||
|
<summary>
|
||||||
|
Override属性
|
||||||
|
</summary>
|
||||||
|
<param name="typeBuilder"></param>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.Build">
|
||||||
|
<summary>
|
||||||
|
Emit动态创建出Class - Type
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.FirstCharToLower(System.String)">
|
||||||
|
<summary>
|
||||||
|
首字母小写
|
||||||
|
</summary>
|
||||||
|
<param name="input"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.Extensions.DynamicEntity.DynamicCompileBuilder.FirstCharToUpper(System.String)">
|
||||||
|
<summary>
|
||||||
|
首字母大写
|
||||||
|
</summary>
|
||||||
|
<param name="input"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
<member name="M:FreeSql.Extensions.EntityUtil.EntityUtilExtensions.GetEntityKeyString(IFreeSql,System.Type,System.Object,System.Boolean,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null
|
获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null
|
||||||
@ -5769,6 +5845,28 @@
|
|||||||
请使用 fsql.InsertDict(dict) 方法插入字典数据
|
请使用 fsql.InsertDict(dict) 方法插入字典数据
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalDynamicEntityExtensions.DynamicEntity(FreeSql.ICodeFirst,System.String,System.Attribute[])">
|
||||||
|
<summary>
|
||||||
|
动态构建Class Type
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalDynamicEntityExtensions.CreateInstance(FreeSql.Internal.Model.TableInfo,System.Collections.Generic.Dictionary{System.String,System.Object})">
|
||||||
|
<summary>
|
||||||
|
根据字典,创建 table 对应的实体对象
|
||||||
|
</summary>
|
||||||
|
<param name="table"></param>
|
||||||
|
<param name="dict"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSqlGlobalDynamicEntityExtensions.CreateDictionary(FreeSql.Internal.Model.TableInfo,System.Object)">
|
||||||
|
<summary>
|
||||||
|
根据实体对象,创建 table 对应的字典
|
||||||
|
</summary>
|
||||||
|
<param name="table"></param>
|
||||||
|
<param name="instance"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSqlGlobalExpressionCallExtensions.Between(System.DateTime,System.DateTime,System.DateTime)">
|
<member name="M:FreeSqlGlobalExpressionCallExtensions.Between(System.DateTime,System.DateTime,System.DateTime)">
|
||||||
<summary>
|
<summary>
|
||||||
C#: that >= between && that <= and<para></para>
|
C#: that >= between && that <= and<para></para>
|
||||||
@ -6285,115 +6383,3 @@
|
|||||||
</member>
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
`0})">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体集合
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.InsertOrUpdate``1">
|
|
||||||
<summary>
|
|
||||||
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
|
||||||
MySql 5.6+: on duplicate key update<para></para>
|
|
||||||
PostgreSQL 9.4+: on conflict do update<para></para>
|
|
||||||
SqlServer 2008+: merge into<para></para>
|
|
||||||
Oracle 11+: merge into<para></para>
|
|
||||||
Sqlite: replace into<para></para>
|
|
||||||
达梦: merge into<para></para>
|
|
||||||
人大金仓:on conflict do update<para></para>
|
|
||||||
神通:merge into<para></para>
|
|
||||||
MsAccess:不支持<para></para>
|
|
||||||
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Update``1">
|
|
||||||
<summary>
|
|
||||||
修改数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Update``1(System.Object)">
|
|
||||||
<summary>
|
|
||||||
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Select``1">
|
|
||||||
<summary>
|
|
||||||
查询数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Select``1(System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Delete``1">
|
|
||||||
<summary>
|
|
||||||
删除数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Delete``1(System.Object)">
|
|
||||||
<summary>
|
|
||||||
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Transaction(System.Action)">
|
|
||||||
<summary>
|
|
||||||
开启事务(不支持异步)<para></para>
|
|
||||||
v1.5.0 关闭了线程事务超时自动提交的机制
|
|
||||||
</summary>
|
|
||||||
<param name="handler">事务体 () => {}</param>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Transaction(System.Data.IsolationLevel,System.Action)">
|
|
||||||
<summary>
|
|
||||||
开启事务(不支持异步)<para></para>
|
|
||||||
v1.5.0 关闭了线程事务超时自动提交的机制
|
|
||||||
</summary>
|
|
||||||
<param name="isolationLevel"></param>
|
|
||||||
<param name="handler">事务体 () => {}</param>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.Ado">
|
|
||||||
<summary>
|
|
||||||
数据库访问对象
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.Aop">
|
|
||||||
<summary>
|
|
||||||
所有拦截方法都在这里
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.CodeFirst">
|
|
||||||
<summary>
|
|
||||||
CodeFirst 模式开发相关方法
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.DbFirst">
|
|
||||||
<summary>
|
|
||||||
DbFirst 模式开发相关方法
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.GlobalFilter">
|
|
||||||
<summary>
|
|
||||||
全局过滤设置,可默认附加为 Select/Update/Delete 条件
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
</members>
|
|
||||||
</doc>
|
|
||||||
|
@ -26,7 +26,7 @@ namespace FreeSql.Internal.Model
|
|||||||
public bool DisableSyncStructure { get; set; }
|
public bool DisableSyncStructure { get; set; }
|
||||||
public string Comment { get; set; }
|
public string Comment { get; set; }
|
||||||
public bool IsRereadSql { get; internal set; }
|
public bool IsRereadSql { get; internal set; }
|
||||||
public bool IsDictionaryType { get; internal set; }
|
public bool IsDictionaryType { get; set; }
|
||||||
|
|
||||||
public IAsTable AsTableImpl { get; internal set; }
|
public IAsTable AsTableImpl { get; internal set; }
|
||||||
public ColumnInfo AsTableColumn { get; internal set; }
|
public ColumnInfo AsTableColumn { get; internal set; }
|
||||||
|
@ -112,15 +112,85 @@ namespace FreeSql.Internal
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤
|
if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤
|
||||||
|
|
||||||
|
var col = ColumnAttributeToInfo(trytb, entityDefault, p.Name, p.PropertyType, setMethod == null, ref colattr, tp, common);
|
||||||
|
if (col == null) continue;
|
||||||
|
|
||||||
|
if (propsComment != null && propsComment.TryGetValue(p.Name, out var trycomment))
|
||||||
|
col.Comment = trycomment;
|
||||||
|
if (string.IsNullOrEmpty(col.Comment) && propsCommentByDescAttr != null && propsCommentByDescAttr.TryGetValue(p.Name, out trycomment))
|
||||||
|
col.Comment = trycomment;
|
||||||
|
|
||||||
|
trytb.Columns.Add(colattr.Name, col);
|
||||||
|
trytb.ColumnsByCs.Add(p.Name, col);
|
||||||
|
columnsList.Add(col);
|
||||||
|
}
|
||||||
|
|
||||||
|
var indexes = common.GetEntityIndexAttribute(trytb.Type);
|
||||||
|
AuditTableInfo(trytb, tbattr, indexes, columnsList, common);
|
||||||
|
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
|
||||||
|
|
||||||
|
#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
|
||||||
|
var trytbTypeName = trytb.Type.DisplayCsharp();
|
||||||
|
var trytbTypeLazyName = default(string);
|
||||||
|
StringBuilder cscode = null;
|
||||||
|
if (common.CodeFirst.IsLazyLoading && propsLazy.Any())
|
||||||
|
{
|
||||||
|
if (trytb.Type.IsPublic == false && trytb.Type.IsNestedPublic == false) throw new Exception(CoreStrings.LazyLoading_EntityMustDeclarePublic(trytbTypeName));
|
||||||
|
|
||||||
|
trytbTypeLazyName = $"FreeSqlLazyEntity__{Regex.Replace(trytbTypeName, @"[^\w\d]", "_")}";
|
||||||
|
|
||||||
|
cscode = new StringBuilder();
|
||||||
|
cscode.AppendLine("using System;")
|
||||||
|
.AppendLine("using FreeSql.DataAnnotations;")
|
||||||
|
.AppendLine("using System.Collections.Generic;")
|
||||||
|
.AppendLine("using System.Linq;")
|
||||||
|
.AppendLine()
|
||||||
|
.Append("public class ").Append(trytbTypeLazyName).Append(" : ").Append(trytbTypeName).AppendLine(" {")
|
||||||
|
.AppendLine(" private IFreeSql __fsql_orm__ { get; set; }\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
var cscodeLength = cscode?.Length ?? 0;
|
||||||
|
foreach (var pnv in propsNavObjs)
|
||||||
|
{
|
||||||
|
var vp = propsLazy.Where(a => a.Item1 == pnv).FirstOrDefault();
|
||||||
|
var isLazy = vp != null && vp.Item1 != null && !string.IsNullOrEmpty(trytbTypeLazyName);
|
||||||
|
|
||||||
|
AddTableRef(common, trytb, pnv, isLazy, vp, cscode);
|
||||||
|
}
|
||||||
|
if (cscode?.Length > cscodeLength)
|
||||||
|
{
|
||||||
|
cscode.AppendLine("}");
|
||||||
|
Assembly assembly = null;
|
||||||
|
if (MethodLazyLoadingComplier.Value == null) throw new Exception(CoreStrings.Install_FreeSql_Extensions_LazyLoading);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
assembly = MethodLazyLoadingComplier.Value.Invoke(null, new object[] { cscode.ToString() }) as Assembly;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception(CoreStrings.LazyLoading_CompilationError(trytbTypeName, ex.Message, cscode));
|
||||||
|
}
|
||||||
|
var type = assembly.GetExportedTypes()/*.DefinedTypes*/.Where(a => a.FullName.EndsWith(trytbTypeLazyName)).FirstOrDefault();
|
||||||
|
trytb.TypeLazy = type;
|
||||||
|
trytb.TypeLazySetOrm = type.GetProperty("__fsql_orm__", BindingFlags.Instance | BindingFlags.NonPublic).GetSetMethod(true);
|
||||||
|
tbc.AddOrUpdate(type, trytb, (oldkey, oldval) => trytb);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
return tbc.TryGetValue(entity, out var trytb2) ? trytb2 : trytb;
|
||||||
|
}
|
||||||
|
public static ColumnInfo ColumnAttributeToInfo(TableInfo trytb, object entityDefault, string csName, Type mapType, bool isIgnore, ref ColumnAttribute colattr, DbInfoResult tp, CommonUtils common)
|
||||||
|
{
|
||||||
var colattrIsNullable = colattr?._IsNullable;
|
var colattrIsNullable = colattr?._IsNullable;
|
||||||
var colattrIsNull = colattr == null;
|
var colattrIsNull = colattr == null;
|
||||||
if (colattr == null)
|
if (colattr == null)
|
||||||
colattr = new ColumnAttribute
|
colattr = new ColumnAttribute
|
||||||
{
|
{
|
||||||
Name = p.Name,
|
Name = csName,
|
||||||
DbType = tp.dbtypeFull,
|
DbType = tp.dbtypeFull,
|
||||||
IsNullable = tp.isnullable ?? true,
|
IsNullable = tp.isnullable ?? true,
|
||||||
MapType = p.PropertyType
|
MapType = mapType
|
||||||
};
|
};
|
||||||
if (colattr._IsNullable == null) colattr._IsNullable = tp?.isnullable;
|
if (colattr._IsNullable == null) colattr._IsNullable = tp?.isnullable;
|
||||||
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
|
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
|
||||||
@ -136,7 +206,7 @@ namespace FreeSql.Internal
|
|||||||
if (colattrIsNull == false && colattrIsNullable == false && colattr.DbType.Contains("NOT NULL") == false) colattr.DbType = Regex.Replace(colattr.DbType, @"\bNULL\b", "").Trim() + " NOT NULL";
|
if (colattrIsNull == false && colattrIsNullable == false && colattr.DbType.Contains("NOT NULL") == false) colattr.DbType = Regex.Replace(colattr.DbType, @"\bNULL\b", "").Trim() + " NOT NULL";
|
||||||
if (colattr._IsNullable == null && tp != null && tp.isnullable == null) colattr.IsNullable = tp.dbtypeFull.Contains("NOT NULL") == false;
|
if (colattr._IsNullable == null && tp != null && tp.isnullable == null) colattr.IsNullable = tp.dbtypeFull.Contains("NOT NULL") == false;
|
||||||
if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false;
|
if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false;
|
||||||
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;
|
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = csName;
|
||||||
if (common.CodeFirst.IsSyncStructureToLower) colattr.Name = colattr.Name.ToLower();
|
if (common.CodeFirst.IsSyncStructureToLower) colattr.Name = colattr.Name.ToLower();
|
||||||
if (common.CodeFirst.IsSyncStructureToUpper) colattr.Name = colattr.Name.ToUpper();
|
if (common.CodeFirst.IsSyncStructureToUpper) colattr.Name = colattr.Name.ToUpper();
|
||||||
|
|
||||||
@ -156,31 +226,27 @@ namespace FreeSql.Internal
|
|||||||
});
|
});
|
||||||
if (colattr.IsIdentity == true && colattr.MapType.IsNumberType() == false)
|
if (colattr.IsIdentity == true && colattr.MapType.IsNumberType() == false)
|
||||||
colattr.IsIdentity = false;
|
colattr.IsIdentity = false;
|
||||||
if (setMethod == null) colattr.IsIgnore = true;
|
if (isIgnore) colattr.IsIgnore = true;
|
||||||
|
|
||||||
var col = new ColumnInfo
|
var col = new ColumnInfo
|
||||||
{
|
{
|
||||||
Table = trytb,
|
Table = trytb,
|
||||||
CsName = p.Name,
|
CsName = csName,
|
||||||
CsType = p.PropertyType,
|
CsType = mapType,
|
||||||
Attribute = colattr
|
Attribute = colattr
|
||||||
};
|
};
|
||||||
if (propsComment != null && propsComment.TryGetValue(p.Name, out var trycomment))
|
|
||||||
col.Comment = trycomment;
|
|
||||||
if (string.IsNullOrEmpty(col.Comment) && propsCommentByDescAttr != null && propsCommentByDescAttr.TryGetValue(p.Name, out trycomment))
|
|
||||||
col.Comment = trycomment;
|
|
||||||
|
|
||||||
if (colattr.IsIgnore)
|
if (colattr.IsIgnore)
|
||||||
{
|
{
|
||||||
trytb.ColumnsByCsIgnore.Add(p.Name, col);
|
trytb.ColumnsByCsIgnore.Add(csName, col);
|
||||||
continue;
|
return null;
|
||||||
}
|
}
|
||||||
object defaultValue = null;
|
object defaultValue = null;
|
||||||
if (entityDefault != null) defaultValue = trytb.Properties[p.Name].GetValue(entityDefault, null);
|
if (entityDefault != null) defaultValue = trytb.Properties[csName].GetValue(entityDefault, null);
|
||||||
if (p.PropertyType.IsEnum)
|
if (defaultValue != null && mapType.IsEnum)
|
||||||
{
|
{
|
||||||
var isEqualsEnumValue = false;
|
var isEqualsEnumValue = false;
|
||||||
var enumValues = Enum.GetValues(p.PropertyType);
|
var enumValues = Enum.GetValues(mapType);
|
||||||
for (var a = 0; a < enumValues.Length; a++)
|
for (var a = 0; a < enumValues.Length; a++)
|
||||||
if (object.Equals(defaultValue, enumValues.GetValue(a)))
|
if (object.Equals(defaultValue, enumValues.GetValue(a)))
|
||||||
{
|
{
|
||||||
@ -190,7 +256,7 @@ namespace FreeSql.Internal
|
|||||||
if (isEqualsEnumValue == false && enumValues.Length > 0)
|
if (isEqualsEnumValue == false && enumValues.Length > 0)
|
||||||
defaultValue = enumValues.GetValue(0);
|
defaultValue = enumValues.GetValue(0);
|
||||||
}
|
}
|
||||||
if (defaultValue != null && p.PropertyType != colattr.MapType) defaultValue = Utils.GetDataReaderValue(colattr.MapType, defaultValue);
|
if (defaultValue != null && mapType != colattr.MapType) defaultValue = Utils.GetDataReaderValue(colattr.MapType, defaultValue);
|
||||||
if (defaultValue == null) defaultValue = tp?.defaultValue;
|
if (defaultValue == null) defaultValue = tp?.defaultValue;
|
||||||
if (colattr.IsNullable == false && defaultValue == null)
|
if (colattr.IsNullable == false && defaultValue == null)
|
||||||
{
|
{
|
||||||
@ -406,12 +472,12 @@ namespace FreeSql.Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (trytb.Columns.ContainsKey(colattr.Name)) throw new Exception(CoreStrings.Duplicate_ColumnAttribute(colattr.Name));
|
if (trytb.Columns.ContainsKey(colattr.Name)) throw new Exception(CoreStrings.Duplicate_ColumnAttribute(colattr.Name));
|
||||||
if (trytb.ColumnsByCs.ContainsKey(p.Name)) throw new Exception(CoreStrings.Duplicate_PropertyName(p.Name));
|
if (trytb.ColumnsByCs.ContainsKey(csName)) throw new Exception(CoreStrings.Duplicate_PropertyName(csName));
|
||||||
|
|
||||||
trytb.Columns.Add(colattr.Name, col);
|
return col;
|
||||||
trytb.ColumnsByCs.Add(p.Name, col);
|
|
||||||
columnsList.Add(col);
|
|
||||||
}
|
}
|
||||||
|
public static void AuditTableInfo(TableInfo trytb, TableAttribute tbattr, IEnumerable<IndexAttribute> indexes, List<ColumnInfo> columnsList, CommonUtils common)
|
||||||
|
{
|
||||||
trytb.VersionColumn = trytb.Columns.Values.Where(a => a.Attribute.IsVersion == true).LastOrDefault();
|
trytb.VersionColumn = trytb.Columns.Values.Where(a => a.Attribute.IsVersion == true).LastOrDefault();
|
||||||
if (trytb.VersionColumn != null)
|
if (trytb.VersionColumn != null)
|
||||||
{
|
{
|
||||||
@ -478,7 +544,6 @@ namespace FreeSql.Internal
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
//索引和唯一键
|
//索引和唯一键
|
||||||
var indexes = common.GetEntityIndexAttribute(trytb.Type);
|
|
||||||
foreach (var index in indexes)
|
foreach (var index in indexes)
|
||||||
{
|
{
|
||||||
var val = index.Fields?.Trim(' ', '\t', ',');
|
var val = index.Fields?.Trim(' ', '\t', ',');
|
||||||
@ -583,57 +648,6 @@ namespace FreeSql.Internal
|
|||||||
.Concat(columnsList.Where(a => a.Attribute.Position == 0))
|
.Concat(columnsList.Where(a => a.Attribute.Position == 0))
|
||||||
.Concat(columnsList.Where(a => a.Attribute.Position < 0).OrderBy(a => a.Attribute.Position)).ToArray();
|
.Concat(columnsList.Where(a => a.Attribute.Position < 0).OrderBy(a => a.Attribute.Position)).ToArray();
|
||||||
trytb.ColumnsByCanUpdateDbUpdateValue = columnsList.Where(a => a.Attribute.CanUpdate == true && string.IsNullOrEmpty(a.DbUpdateValue) == false).ToArray();
|
trytb.ColumnsByCanUpdateDbUpdateValue = columnsList.Where(a => a.Attribute.CanUpdate == true && string.IsNullOrEmpty(a.DbUpdateValue) == false).ToArray();
|
||||||
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
|
|
||||||
|
|
||||||
#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
|
|
||||||
var trytbTypeName = trytb.Type.DisplayCsharp();
|
|
||||||
var trytbTypeLazyName = default(string);
|
|
||||||
StringBuilder cscode = null;
|
|
||||||
if (common.CodeFirst.IsLazyLoading && propsLazy.Any())
|
|
||||||
{
|
|
||||||
if (trytb.Type.IsPublic == false && trytb.Type.IsNestedPublic == false) throw new Exception(CoreStrings.LazyLoading_EntityMustDeclarePublic(trytbTypeName));
|
|
||||||
|
|
||||||
trytbTypeLazyName = $"FreeSqlLazyEntity__{Regex.Replace(trytbTypeName, @"[^\w\d]", "_")}";
|
|
||||||
|
|
||||||
cscode = new StringBuilder();
|
|
||||||
cscode.AppendLine("using System;")
|
|
||||||
.AppendLine("using FreeSql.DataAnnotations;")
|
|
||||||
.AppendLine("using System.Collections.Generic;")
|
|
||||||
.AppendLine("using System.Linq;")
|
|
||||||
.AppendLine()
|
|
||||||
.Append("public class ").Append(trytbTypeLazyName).Append(" : ").Append(trytbTypeName).AppendLine(" {")
|
|
||||||
.AppendLine(" private IFreeSql __fsql_orm__ { get; set; }\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
var cscodeLength = cscode?.Length ?? 0;
|
|
||||||
foreach (var pnv in propsNavObjs)
|
|
||||||
{
|
|
||||||
var vp = propsLazy.Where(a => a.Item1 == pnv).FirstOrDefault();
|
|
||||||
var isLazy = vp != null && vp.Item1 != null && !string.IsNullOrEmpty(trytbTypeLazyName);
|
|
||||||
|
|
||||||
AddTableRef(common, trytb, pnv, isLazy, vp, cscode);
|
|
||||||
}
|
|
||||||
if (cscode?.Length > cscodeLength)
|
|
||||||
{
|
|
||||||
cscode.AppendLine("}");
|
|
||||||
Assembly assembly = null;
|
|
||||||
if (MethodLazyLoadingComplier.Value == null) throw new Exception(CoreStrings.Install_FreeSql_Extensions_LazyLoading);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
assembly = MethodLazyLoadingComplier.Value.Invoke(null, new object[] { cscode.ToString() }) as Assembly;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception(CoreStrings.LazyLoading_CompilationError(trytbTypeName, ex.Message, cscode));
|
|
||||||
}
|
|
||||||
var type = assembly.GetExportedTypes()/*.DefinedTypes*/.Where(a => a.FullName.EndsWith(trytbTypeLazyName)).FirstOrDefault();
|
|
||||||
trytb.TypeLazy = type;
|
|
||||||
trytb.TypeLazySetOrm = type.GetProperty("__fsql_orm__", BindingFlags.Instance | BindingFlags.NonPublic).GetSetMethod(true);
|
|
||||||
tbc.AddOrUpdate(type, trytb, (oldkey, oldval) => trytb);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
return tbc.TryGetValue(entity, out var trytb2) ? trytb2 : trytb;
|
|
||||||
}
|
}
|
||||||
public static void AddTableRef(CommonUtils common, TableInfo trytb, PropertyInfo pnv, bool isLazy, NativeTuple<PropertyInfo, bool, bool, MethodInfo, MethodInfo> vp, StringBuilder cscode)
|
public static void AddTableRef(CommonUtils common, TableInfo trytb, PropertyInfo pnv, bool isLazy, NativeTuple<PropertyInfo, bool, bool, MethodInfo, MethodInfo> vp, StringBuilder cscode)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user