代码之家  ›  专栏  ›  技术社区  ›  alyawdi

C#中的ValueObject获取错误实体类型“SkillLevel”需要定义主键

  •  0
  • alyawdi  · 技术社区  · 1 年前

    这是我的 SkillLevel valueobject类,该类应用于 EmployeeSkillType 联接表:

    using System.Runtime.CompilerServices;
    
    namespace sales.Domain.Common.ValueObjects
    {
        public record SkillLevel 
        {
            List<Skill> Skill; 
            List<Level> Level; 
    
            private SkillLevel() { }
    
            public SkillLevel(List<Skill> skill, List<Level> level) 
            {
                Skill = skill;
                Level = level;
            }
        }
    }
    

    这就是我使用它的地方:

    using Microsoft.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore.Metadata.Builders;
    
    using Pluralize.NET;
    using sales.Domain.Common.BaseEntities;
    using sales.Domain.Entities.Payroll;
    
    namespace sales.Infrastructure.Data.Configs.Payroll
    {
        internal class EmployeeSkillTypeConfiguration : IEntityTypeConfiguration<EmployeeSkillType>
        {
            public void Configure(EntityTypeBuilder<EmployeeSkillType> builder)
            {
                builder.ToTable(new Pluralizer().Pluralize(nameof(EmployeeSkillType)));
                builder.HasKey(ii => new { ii.EmployeeGuid, ii.SkillTypeGuid });
                builder.HasOne(e => e.Employee)
                    .WithMany(es => es.EmployeeSkillType);
                builder.HasOne(st => st.SkillType)
                    .WithMany(es => es.EmployeeSkillType);
                builder.HasMany(sl => sl.SKillLevels).WithOne();
    
                builder.Navigation(e => e.Employee).AutoInclude();
                builder.Navigation(st => st.SkillType).AutoInclude();
            }
        }
    }
    

    我收到这个错误

    实体类型“SkillLevel”需要定义主键。如果您打算使用无钥匙实体类型,请在“OnModelCreating”中调用“HasNoKey”。有关无钥匙实体类型的更多信息,

    我没有尝试太多——我把它改成了jsonb,但我又犯了一个错误

    0 回复  |  直到 1 年前