Replies: 4 comments 10 replies
-
想确认一下场景,会存在多次 ConfigEntity AuditEntity 的情况吗? 目前元数据信息是全局共享,后修改的会影响前面,不适合多次修改配置。 |
Beta Was this translation helpful? Give feedback.
4 replies
-
fsql.CodeFirst.ConfigEntity<BizEntity1>(t => t.Property(p => p.CreatedTime).ServerTime(DateTimeKind.Local));
fsql.CodeFirst.ConfigEntity<AuditEntity>(t => t.Property(p => p.CreatedTime).ServerTime(DateTimeKind.Utc)); 确定机制,这种设置 BizEntity1 仍然是 Local |
Beta Was this translation helpful? Give feedback.
1 reply
-
using FreeSql.Internal;
using FreeSql.Internal.Model;
using (var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, "Data Source=:memory:")
.UseAutoSyncStructure(true)
.UseMappingPriority(MappingPriorityType.Attribute, MappingPriorityType.Aop, MappingPriorityType.FluentApi)
.Build())
{
ColumnInfo localFunc1() =>fsql.CodeFirst.GetTableByEntity(typeof(ModelAopConfigEntity01)).Columns["CreatedTime"];
ColumnInfo localFunc2() =>fsql.CodeFirst.GetTableByEntity(typeof(ModelAopConfigEntity02)).Columns["CreatedTime"];
Assert.Equal(DateTimeKind.Local, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Local, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntityBase>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Utc));
Assert.Equal(DateTimeKind.Utc, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Utc, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntityBase>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Local));
Assert.Equal(DateTimeKind.Local, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Local, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntity01>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Utc));
Assert.Equal(DateTimeKind.Utc, localFunc1().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntity02>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Utc));
Assert.Equal(DateTimeKind.Utc, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntityBase>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Local));
Assert.Equal(DateTimeKind.Utc, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Utc, localFunc2().Attribute.ServerTime);
}
class ModelAopConfigEntityBase
{
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
public virtual DateTime CreatedTime { get; set; }
}
class ModelAopConfigEntity01 : ModelAopConfigEntityBase
{
}
class ModelAopConfigEntity02 : ModelAopConfigEntityBase
{
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
v3.2.666-preview20220604 已发布 |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
场景如下:
有个Entity基类:
若干 业务Entity 继承自 AuditEntity,因为不同项目(这些项目共用 业务Entity 所在项目)要求 CreatedTime 存储的值不一样,某些要求存 Local,某些要求存 Utc,因此 AuditEntity.CreatedTime 没有直接写死 ServerTime,想着用 fsql.CodeFirst.ConfigEntity 来设置:
发现不行,必须把继承 AuditEntity 的所有 业务Entity 的CreatedTime都设置一下才行:
是否可考虑让只设置父类 AuditEntity 的就可以了么?
Beta Was this translation helpful? Give feedback.
All reactions