mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 优化 DbContext/Repository Update 实体有 ServerTime 既使无状态变化也必然更新的逻辑;
This commit is contained in:
parent
46ad51c7e0
commit
91522386b1
@ -538,14 +538,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>
|
||||||
|
@ -593,6 +593,55 @@ namespace FreeSql.Tests
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
[Fact]
|
||||||
|
public void BeginEditIdentity()
|
||||||
|
{
|
||||||
|
g.sqlite.Delete<BeginEdit02>().Where("1=1").ExecuteAffrows();
|
||||||
|
var repo = g.sqlite.GetRepository<BeginEdit02>();
|
||||||
|
var cts = new[] {
|
||||||
|
new BeginEdit02 { Name = "分类1" },
|
||||||
|
new BeginEdit02 { Name = "分类1_1" },
|
||||||
|
new BeginEdit02 { Name = "分类1_2" },
|
||||||
|
new BeginEdit02 { Name = "分类1_3" },
|
||||||
|
new BeginEdit02 { Name = "分类2" },
|
||||||
|
new BeginEdit02 { Name = "分类2_1" },
|
||||||
|
new BeginEdit02 { Name = "分类2_2" }
|
||||||
|
}.ToList();
|
||||||
|
repo.Insert(cts);
|
||||||
|
|
||||||
|
repo.BeginEdit(cts);
|
||||||
|
|
||||||
|
cts.Add(new BeginEdit02 { Name = "分类2_3" });
|
||||||
|
cts[0].Name = "123123";
|
||||||
|
cts.RemoveAt(1);
|
||||||
|
|
||||||
|
Assert.Equal(3, repo.EndEdit());
|
||||||
|
|
||||||
|
g.sqlite.Delete<BeginEdit02>().Where("1=1").ExecuteAffrows();
|
||||||
|
repo = g.sqlite.GetRepository<BeginEdit02>();
|
||||||
|
cts = repo.Select.ToList();
|
||||||
|
repo.BeginEdit(cts);
|
||||||
|
|
||||||
|
cts.AddRange(new[] {
|
||||||
|
new BeginEdit02 { Name = "分类1" },
|
||||||
|
new BeginEdit02 { Name = "分类1_1" },
|
||||||
|
new BeginEdit02 { Name = "分类1_2" },
|
||||||
|
new BeginEdit02 { Name = "分类1_3" },
|
||||||
|
new BeginEdit02 { Name = "分类2" },
|
||||||
|
new BeginEdit02 { Name = "分类2_1" },
|
||||||
|
new BeginEdit02 { Name = "分类2_2" }
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal(7, repo.EndEdit());
|
||||||
|
}
|
||||||
|
class BeginEdit02
|
||||||
|
{
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
[Column(ServerTime = DateTimeKind.Utc)]
|
||||||
|
public DateTime UpdateTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void OrmScoped()
|
public void OrmScoped()
|
||||||
|
@ -604,7 +604,15 @@ namespace FreeSql.Extensions.EntityUtil
|
|||||||
exps.Add(Expression.Label(returnTarget, Expression.Constant(new string[0])));
|
exps.Add(Expression.Label(returnTarget, Expression.Constant(new string[0])));
|
||||||
return Expression.Lambda<Func<object, object, bool, string[]>>(Expression.Block(new[] { var1Ret, var1Parm, var2Parm }, exps), new[] { parm1, parm2, parm3 }).Compile();
|
return Expression.Lambda<Func<object, object, bool, string[]>>(Expression.Block(new[] { var1Ret, var1Parm, var2Parm }, exps), new[] { parm1, parm2, parm3 }).Compile();
|
||||||
});
|
});
|
||||||
return func(entity1, entity2, isEqual);
|
var result = func(entity1, entity2, isEqual);
|
||||||
|
var tmptb = orm.CodeFirst.GetTableByEntity(entityType);
|
||||||
|
if (tmptb.ColumnsByCanUpdateDbUpdateValue.Length > 0) {
|
||||||
|
if (isEqual && result.Length + tmptb.ColumnsByCanUpdateDbUpdateValue.Length == tmptb.ColumnsByCs.Count)
|
||||||
|
return result.Concat(tmptb.ColumnsByCanUpdateDbUpdateValue.Select(a => a.Attribute.Name)).ToArray();
|
||||||
|
if (!isEqual && result.Length == tmptb.ColumnsByCanUpdateDbUpdateValue.Length)
|
||||||
|
return new string[0];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, string, int>>> _dicSetEntityIncrByWithPropertyName = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, string, int>>>();
|
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, string, int>>> _dicSetEntityIncrByWithPropertyName = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, string, int>>>();
|
||||||
|
@ -17,6 +17,7 @@ namespace FreeSql.Internal.Model
|
|||||||
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public Dictionary<string, ColumnInfo> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, ColumnInfo> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public ColumnInfo[] ColumnsByPosition { get; set; }
|
public ColumnInfo[] ColumnsByPosition { get; set; }
|
||||||
|
public ColumnInfo[] ColumnsByCanUpdateDbUpdateValue { get; set; }
|
||||||
public ColumnInfo[] Primarys { get; set; }
|
public ColumnInfo[] Primarys { get; set; }
|
||||||
public IndexInfo[] Indexes { get; set; }
|
public IndexInfo[] Indexes { get; set; }
|
||||||
public string CsName { get; set; }
|
public string CsName { get; set; }
|
||||||
|
@ -484,6 +484,7 @@ namespace FreeSql.Internal
|
|||||||
trytb.ColumnsByPosition = columnsList.Where(a => a.Attribute.Position > 0).OrderBy(a => a.Attribute.Position)
|
trytb.ColumnsByPosition = columnsList.Where(a => a.Attribute.Position > 0).OrderBy(a => a.Attribute.Position)
|
||||||
.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.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary == true).ToArray();
|
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary == true).ToArray();
|
||||||
if (trytb.Primarys.Any() == false)
|
if (trytb.Primarys.Any() == false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user