相关疑难解决方法(0)

datetime和timestamp之间有什么区别

Sql Server中的datetime和timestamp数据类型有什么区别?

sql-server-2005

51
推荐指数
2
解决办法
2万
查看次数

在EF Core中自动填充Created和LastModified

期待构建一个框架(没有直接使用DbSets的存储库模式)自动填充Created并最后自动修改,而不是通过代码库吐出这些代码.

你能指出我正确的方向如何实现它.

在过去,我尝试在构造函数中填充这些,但是这看起来像是一个讨厌的代码,每次我们从数据库中调出来时,更改跟踪会将实体标记为已修改.

.ctor()
    {
        Created = DateTime.Now;
        LastModified = DateTime.Now;
    }

public interface IHasCreationLastModified
    {
        DateTime Created { get; set; }
        DateTime? LastModified { get; set; }
    }

public class Account : IEntity, IHasCreationLastModified
{
    public long Id { get; set; }

    public DateTime Created { get; set; }
    public DateTime? LastModified { get; set; }
    public virtual IdentityUser IdentityUser { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-core ef-core-2.1

3
推荐指数
2
解决办法
1100
查看次数