Sql Server中的datetime和timestamp数据类型有什么区别?
期待构建一个框架(没有直接使用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)