Closed Sheldon-NULL closed 1 year ago
db.Aop.DataExecuting = (oldValue, entityInfo) =>
{
/*** inset生效 ***/
if (entityInfo.PropertyName == "CreateTime"&&entityInfo.OperationType== DataFilterType.InsertByObject)
{
entityInfo.SetValue(DateTime.Now);//修改CreateTime字段
//entityInfo有字段所有参数
// get value 可以这么写
// var value=entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
}
//特性用法
//if(p.EntityColumnInfo.PropertyInfo.GetCustomAttribute<自定义特性>()!=null
// &&entityInfo.OperationType== DataFilterType.InsertByObject)
//5.1.3.23 更好的支持了特性
//p.IsAnyAttribute<特性>()
//p.GetAttribute<特性>()
/*** update生效 ***/
if (entityInfo.PropertyName =="UpdateTime" && entityInfo.OperationType == DataFilterType.UpdateByObject)
{
entityInfo.SetValue(DateTime.Now);//修改UpdateTime字段
}
//根据当前列修改另一列 可以么写
//if(当前列逻辑==XXX)
//var properyDate = entityInfo.EntityValue.GetType().GetProperty("Date");
//if(properyDate!=null)
//properyDate.SetValue(entityInfo.EntityValue,1);
};
你可先用这个AOP方式实现
这个功能目前只支持了插入,我这2天把更新也支持一下
非常感谢大佬
留着给您更新完,再关闭吧
最新预览本已支持了,更新可以试用了
SqlSugarCoreNoDrive这个包应该没上传更新吧
没有,我现在上传
已发布 勾一下预览
ok,已经用起来了。 然后一个小建议:我觉得这个属性还有优化空间,可以再考虑把DateTime.ToString(),这个有关控制时间格式的重载做进去,甚至像DateTime.Now.AddDays(),这种时间运算也不是不可以考虑的。
这个也计划中,属性自定义方式
查询 插入 更新 有套自定义体系,后面还要支持值对象
这个先关闭有新问题在发新ISSUE
当前是否已经实现对像CreateTime或UpdateTime这种字段,插入或更新能赋予当前时间的值呢?
我的想法如果能做到这种简单写完就能实现就很快
希望能得到解决方案,或者能添加这个功能。