其他分享
首页 > 其他分享> > ioc+ef+core搭建模型映射(三)

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

需要自己配置数据库,以及泛型集合,

标签:core,映射,builder,ef,sysUser,HasMaxLength,Property,ioc,模型
来源: https://www.cnblogs.com/shuaimeng/p/11338802.html