IOC+EF+Core搭建项目框架(三)
/// <summary> /// 表示类别映射配置 /// </summary> public partial class sys_UserMap : NopEntityTypeConfiguration<sys_User> { public override void Configure(EntityTypeBuilder<sys_User> builder) { builder.ToTable(nameof(sys_User)); builder.HasKey(sysUser => sysUser.gid); builder.Property(sysUser => sysUser.userLoginName).HasMaxLength(30).IsRequired(); builder.Property(sysUser => sysUser.userPwd).HasMaxLength(30).IsRequired(); builder.Property(sysUser => sysUser.userEmail).HasMaxLength(50); //builder.Ignore(category => category.AppliedDiscounts); base.Configure(builder); } }
模型必须映射,不然会报找不到模型错误,在NopObjectContext的OnModelCreating会自动加入模型,
demo地址:https://pan.baidu.com/s/1F6MsZs5T8JZbHom_mvIRUA fiyl
需要自己配置数据库,以及泛型集合,
ioc+ef代码基本就封装好,使用如下
然后直接在控制器调用,具体看demo中user的代码
地址:https://gitee.com/cainiaoA/core_22_privilege_system