标签:遇到 ace names key uil builder url lis space
最近在使用.net core 重构博客是,在使用ef core连表查询时,遇到了一些问题。记录一下。
下面是实体代码
BlogEntity
namespace Blog.Service.Entities { public class BlogEntity:BaseEntity { public string Title { get; set; } public string Content { get; set; } public virtual List<BlogLabelEntity> BlogLabels { get; set; } = new List<BlogLabelEntity>(); } }
BlogConfig
namespace Blog.Service.EntityConfig { public class BlogConfig : IEntityTypeConfiguration<BlogEntity> { public void Configure(EntityTypeBuilder<BlogEntity> builder) { builder.ToTable("T_Blogs"); builder.HasKey(u => u.Id); builder.Property(u => u.Title).HasMaxLength(500).IsRequired(); builder.Property(u => u.Content).IsRequired(); } } }
Label
namespace Blog.Service.Entities { public class LabelEntity:BaseEntity { public string Title { get; set; } public string IconUrl { get; set; } public virtual List<BlogLabelEntity> BlogLabels { get; set; } = new List<BlogLabelEntity>(); } }
LabelConfig
namespace Blog.Service.EntityConfig { public class LabelConfig : IEntityTypeConfiguration<LabelEntity> { public void Configure(EntityTypeBuilder<LabelEntity> builder) { builder.ToTable("T_Labels"); builder.HasKey(u => u.Id); builder.Property(u => u.Title).HasMaxLength(50).IsRequired(); builder.Property(u => u.IconUrl).HasMaxLength(500); } } }
BlogLabelEntity
namespace Blog.Service.Entities { public class BlogLabelEntity:BaseEntity { public long BlogId { get; set; } public virtual BlogEntity Blog { get; set; } public long LabelId { get; set; } public virtual LabelEntity Label { get; set; } } }
BlogLabelConfig
这里需要连接blog和label两个表
以blog为例
blogService.GetAll().Include(u => u.BlogLabels).ThenInclude(bl=>bl.Label)
以上为多对多的关联
标签:遇到 ace names key uil builder url lis space
原文地址:https://www.cnblogs.com/c-supreme/p/9955483.html