如何在宁静 MVC 框架上分配 userId
How to assign userId on serenity MVC framework
我想在每个 table 上保存 CreatedBy 和 LastModifiedBy 字段。是否有关于宁静的基本解决方案?
当我设置 fld 字段时出现以下错误:
Severity Code Description Project File Line Suppression State
Error CS0029 Cannot implicitly convert type 'int' to 'Serenity.Data.Int32Field'
private static MyRow.RowFields fld { get { return MyRow.Fields; } }
protected override void SetInternalFields()
{
int userId = ((UserDefinition)Authorization.UserDefinition).UserId;
fld.LastModifiedBy = userId;
fld 是对实体字段(元数据)的引用,而不是实体实例本身。
在 SaveHandler 中,this.Row 引用具有新值的 created/updated 实体,而 this.Old 引用具有新值的实体更新的旧值(有点类似于 SQL 触发器)。
所以你应该写Row.LastModifiedBy = userId;
仅供参考,不要在每个存储库中都这样做,而是在您的实体中实现 IUpdateLogRow (and/or InsertLogRow) 接口,默认保存行为将填充 Insert/Update UserId/Date 字段自动。
在 Serene 中定义一个基行,例如 LoggingRow 示例,以避免必须在每个实体中实现此接口。
我想在每个 table 上保存 CreatedBy 和 LastModifiedBy 字段。是否有关于宁静的基本解决方案? 当我设置 fld 字段时出现以下错误:
Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'int' to 'Serenity.Data.Int32Field'
private static MyRow.RowFields fld { get { return MyRow.Fields; } }
protected override void SetInternalFields()
{
int userId = ((UserDefinition)Authorization.UserDefinition).UserId;
fld.LastModifiedBy = userId;
fld 是对实体字段(元数据)的引用,而不是实体实例本身。
在 SaveHandler 中,this.Row 引用具有新值的 created/updated 实体,而 this.Old 引用具有新值的实体更新的旧值(有点类似于 SQL 触发器)。
所以你应该写Row.LastModifiedBy = userId;
仅供参考,不要在每个存储库中都这样做,而是在您的实体中实现 IUpdateLogRow (and/or InsertLogRow) 接口,默认保存行为将填充 Insert/Update UserId/Date 字段自动。
在 Serene 中定义一个基行,例如 LoggingRow 示例,以避免必须在每个实体中实现此接口。