Json Column Seed Ef 7

Mrbanad 30 Reputation points
2023-10-16T05:30:07.73+00:00

i try to seed My data in To DataBase

but i got this Error:
The seed entity for entity type 'JobState' cannot be added because it has the navigation 'FromInfo' set. To seed relationships, add the entity seed to 'JobState.FromInfo#List ' and specify the foreign key values {'JobStateId'}. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the involved property values.

My Context Config:

modelBuilder.Entity<JobState>().HasData(new JobState{    Id = 1,    Active = true,    Delete = false,    System = true,    JobTypeId = 1,    CreatorId = 1,    CreateDate = DateTime.Now,    Form = "Init",    FromInfo =  new List<BaseInfo>    {        new BaseInfo        {            Title ="ثبت",            Description = null,            Language = 0        }    },    To = "InProgress",    ToInfo = new List<BaseInfo>    {        new BaseInfo        {            Title ="در حال بررسی",            Description = null,            Language =  0        }    },    IsStart = true,    IsEnd = false,    Roles = new List<long>    {        1    },    IsAuto = true,    CanSelect = false,});

modelBuilder.Entity<JobState>(entity => {    entity.Property(e => e.Id).ValueGeneratedNever();    entity.Property(e => e.Active).HasDefaultValueSql("((1))");    entity.HasOne(d => d.JobType).WithMany(p => p.JobStates)        .OnDelete(DeleteBehavior.ClientSetNull)        .HasConstraintName("FK_Table_54_Table_55");        entity.OwnsOne(navigationExpression: jobState => jobState.Roles, buildAction: owned => {        owned.ToJson("Field_15");    });    entity.OwnsOne(navigationExpression: jobState => jobState.FromInfo, buildAction: owned => {        owned.ToJson("Field_10");    });    entity.OwnsOne(navigationExpression: jobState => jobState.ToInfo, buildAction: owned => {        owned.ToJson("Field_12");    });});
[Table("Table_55")]public class JobType : BaseEntity{    [Required]    public List<BaseInfo> Info { get; set; }        [InverseProperty("JobType")]    public virtual ICollection<JobState> JobStates { get; set; } = new List<JobState>();}
[Table("Table_54")]public class JobState : BaseEntity{    [Required]    [Column("Field_09")]    public string Form { get; set; }    [Required]    public List<BaseInfo> FromInfo { get; set; }    [Required]    [Column("Field_11")]    public string To { get; set; }    [Required]    public List<BaseInfo> ToInfo { get; set; }    [Column("Field_13")]    public bool IsStart { get; set; }    [Column("Field_14")]    public bool IsEnd { get; set; }    [Required]    public List<long> Roles { get; set; }    [Column("Field_16")]    public bool IsAuto { get; set; }    [Column("Field_17")]    public bool CanSelect { get; set; }        [Column("Field_18")]    [ForeignKey("Field_18")]    public long JobTypeId { get; set; }    [InverseProperty("JobStates")]    public virtual JobType JobType { get; set; }        [InverseProperty("State")]    public virtual ICollection<JobHistory> JobHistories { get; set; } = new List<JobHistory>();    [InverseProperty("JobState")]    public virtual ICollection<Job> Jobs { get; set; } = new List<Job>();}
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,234 questions
{count} votes