## v0.3.21

- 增加 IUpdate IgnoreColumns 重载方法,支持传入字符串数组忽略修改;
- 完善 FreeSql.DbContext,支持对象操作 + SaveChanges 最后保存操作;
This commit is contained in:
28810
2019-03-21 05:24:50 +08:00
parent d9de8e986b
commit c20a0bbd54
24 changed files with 815 additions and 48 deletions

View File

@ -16,6 +16,12 @@ namespace FreeSql.DataAnnotations {
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public string SelectFilter { get; set; }
internal bool? _RowVersion;
/// <summary>
/// 修改/删除时,启用行版本检查
/// </summary>
public bool RowVersion { get => _RowVersion ?? false; set => _RowVersion = value; }
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
}

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.3.20</Version>
<Version>0.3.21</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

View File

@ -38,6 +38,12 @@ namespace FreeSql {
/// <param name="columns">lambda选择列</param>
/// <returns></returns>
IUpdate<T1> IgnoreColumns(Expression<Func<T1, object>> columns);
/// <summary>
/// 忽略的列
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
IUpdate<T1> IgnoreColumns(string[] columns);
/// <summary>
/// 设置列的新值Set(a => a.Name, "newvalue")

View File

@ -1,4 +1,5 @@
using FreeSql.DataAnnotations;
using FreeSql.Internal.Model;
using System;
namespace FreeSql {
@ -81,5 +82,11 @@ namespace FreeSql {
/// <param name="type"></param>
/// <returns>未使用ConfigEntity配置时返回null</returns>
TableAttribute GetConfigEntity(Type type);
/// <summary>
/// 获取实体类核心配置
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
TableInfo GetTableByEntity(Type type);
}
}

View File

@ -395,7 +395,7 @@ namespace FreeSql.Internal.CommonProvider {
Expression.Assign(readExp, readExpAssign),
Expression.IfThen(Expression.GreaterThan(readExpDataIndex, dataIndexExp),
Expression.Assign(dataIndexExp, readExpDataIndex)),
Expression.Call(typeof(Trace).GetMethod("WriteLine", new Type[]{typeof(string)}), Expression.Call(typeof(string).GetMethod("Concat", new Type[]{typeof(object) }), readExpValue)),
//Expression.Call(typeof(Trace).GetMethod("WriteLine", new Type[]{typeof(string)}), Expression.Call(typeof(string).GetMethod("Concat", new Type[]{typeof(object) }), readExpValue)),
Expression.IfThen(Expression.NotEqual(readExpValue, Expression.Constant(null)),
//Expression.Call(retExp, propGetSetMethod, Expression.Default(prop.PropertyType)),
Expression.Call(retExp, propGetSetMethod, Expression.Convert(readExpValue, prop.PropertyType)))

View File

@ -63,6 +63,11 @@ namespace FreeSql.Internal.CommonProvider {
foreach (var col in cols) _ignore.Add(col, true);
return this;
}
public IUpdate<T1> IgnoreColumns(string[] columns) {
_ignore.Clear();
foreach (var col in columns) _ignore.Add(col, true);
return this;
}
public IUpdate<T1> SetSource(T1 source) => this.SetSource(new[] { source });
public IUpdate<T1> SetSource(IEnumerable<T1> source) {

View File

@ -2,7 +2,7 @@
using System;
namespace FreeSql.Internal.Model {
class ColumnInfo {
public class ColumnInfo {
public TableInfo Table { get; set; }
public string CsName { get; set; }
public Type CsType { get; set; }

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Reflection;
namespace FreeSql.Internal.Model {
class TableInfo {
public class TableInfo {
public Type Type { get; set; }
public Type TypeLazy { get; set; }
public MethodInfo TypeLazySetOrm { get; set; }

View File

@ -13,7 +13,7 @@ using System.Text;
using System.Text.RegularExpressions;
namespace FreeSql.Internal {
class Utils {
public class Utils {
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>> _cacheGetTableByEntity = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>>();
internal static void RemoveTableByEntity(Type entity, CommonUtils common) {
@ -997,7 +997,7 @@ namespace FreeSql.Internal {
static MethodInfo MethodJTokenParse = typeof(JToken).GetMethod("Parse", new[] { typeof(string) });
static MethodInfo MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) });
static MethodInfo MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) });
internal static Expression GetDataReaderValueBlockExpression(Type type, Expression value) {
public static Expression GetDataReaderValueBlockExpression(Type type, Expression value) {
var returnTarget = Expression.Label(typeof(object));
var valueExp = Expression.Variable(typeof(object), "locvalue");
Func<Expression> funcGetExpression = () => {
@ -1084,7 +1084,7 @@ namespace FreeSql.Internal {
Expression.Label(returnTarget, Expression.Default(typeof(object)))
);
}
internal static object GetDataReaderValue(Type type, object value) {
public static object GetDataReaderValue(Type type, object value) {
if (value == null || value == DBNull.Value) return null;
var func = _dicGetDataReaderValue.GetOrAdd(type, k1 => new ConcurrentDictionary<Type, Func<object, object>>()).GetOrAdd(value.GetType(), valueType => {
var parmExp = Expression.Parameter(typeof(object), "value");

View File

@ -277,5 +277,6 @@ where a.table_schema in ({0}) and a.table_name in ({1})".FormatMySql(tboldname ?
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
public TableInfo GetTableByEntity(Type type) => _commonUtils.GetTableByEntity(type);
}
}

View File

@ -315,5 +315,6 @@ where owner={{0}} and table_name={{1}}".FormatOracleSQL(tboldname ?? tbname);
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
public TableInfo GetTableByEntity(Type type) => _commonUtils.GetTableByEntity(type);
}
}

View File

@ -329,5 +329,6 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
public TableInfo GetTableByEntity(Type type) => _commonUtils.GetTableByEntity(type);
}
}

View File

@ -299,5 +299,6 @@ use " + database, tboldname ?? tbname);
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
public TableInfo GetTableByEntity(Type type) => _commonUtils.GetTableByEntity(type);
}
}

View File

@ -245,5 +245,6 @@ namespace FreeSql.Sqlite {
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
public TableAttribute GetConfigEntity(Type type) => _commonUtils.GetConfigEntity(type);
public TableInfo GetTableByEntity(Type type) => _commonUtils.GetTableByEntity(type);
}
}