1.在.NET Core项目中使用Nuget引用包 

Sql Server 请安装 Microsoft.EntityFrameworkCore.SqlServer

 

2.添加实体类

    [Table("AdminUsers")]
    public class AdminUser
    {
        [Key]
        public string Id { get; set; }

        [DisplayName("名称")]
        [MaxLength(30), Required]
        public string Name { get; set; }
        
        [DisplayName("创建日期")]
        public DateTimeOffset Created { get; set; }

        [DisplayName("创建日期")]
        public DateTimeOffset Modified { get; set; }

        public virtual void Create(WFDbContext db)
        {
            Id = Guid.NewGuid().ToString();
            Created = Modified = DateTimeOffset.Now;
        }

        public virtual void Modify(WFDbContext db)
        {
            Modified = DateTimeOffset.Now;
            db.Entry(this).State = EntityState.Modified;
        }
    }
View Code

相关文章:

  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2018-12-13
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案