- 动态操作表结构相关的 API

This commit is contained in:
2881099
2023-05-04 21:46:11 +08:00
parent a0f4c9022d
commit 235a2c2636
4 changed files with 44 additions and 101 deletions

View File

@@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using FreeSql.DataAnnotations;
using FreeSql.Internal;
namespace FreeSql.Extensions
{
#if net40 || NETSTANDARD2_0
#else
public static class CodeFirstExtensions
{
/// <summary>
/// 动态构建Class Type
/// </summary>
/// <returns></returns>
public static DynamicCompileBuilder DynamicEntity(this ICodeFirst codeFirst, string className,
TableAttribute tableAttribute)
{
return new DynamicCompileBuilder().SetClass(className, tableAttribute);
}
}
#endif
}

View File

@@ -1,5 +1,6 @@
using FreeSql;
using FreeSql.DataAnnotations;
using FreeSql.Internal;
using FreeSql.Internal.CommonProvider;
using FreeSql.Internal.Model;
using FreeSql.Internal.ObjectPool;
@@ -1299,4 +1300,18 @@ SELECT ");
return NativeTuple.Create(query, af, sql);
}
#endregion
#region DynamicEntity
#if net40 || NETSTANDARD2_0
#else
/// <summary>
/// 动态构建Class Type
/// </summary>
/// <returns></returns>
public static DynamicCompileBuilder DynamicEntity(this ICodeFirst codeFirst, string className, TableAttribute tableAttribute)
{
return new DynamicCompileBuilder(className, tableAttribute);
}
#endif
#endregion
}

View File

@@ -1,40 +0,0 @@
using FreeSql.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DynamicBuilder
{
#if net40 || NETSTANDARD2_0
#else
public static class TypeExtensions
{
/// <summary>
/// 根据动态构建的Class Type生成实例并进行属性赋值
/// </summary>
/// <param name="type"></param>
/// <param name="porpertys"></param>
/// <returns></returns>
public static object CreateDynamicEntityInstance(this Type type, IFreeSql fsql,
Dictionary<string, object> porpertys)
{
return DynamicCompileBuilder.CreateObjectByTypeByCodeFirst(fsql, type, porpertys);
}
/// <summary>
/// 设置对象属性值
/// </summary>
/// <param name="fsql"></param>
/// <returns></returns>
public static void SetPropertyValue(this Type type, IFreeSql fsql, ref object obj, string propertyName,
object propertyValue)
{
var table = fsql.CodeFirst.GetTableByEntity(obj.GetType());
table.ColumnsByCs[propertyName].SetValue(obj, propertyValue);
}
}
#endif
}