元数据集合中不存在身份为 'PmData.SafetyRequirement_Assets' 的成员。\r\nParameter 名称:身份

The member with identity 'PmData.SafetyRequirement_Assets' does not exist in the metadata collection.\r\nParameter name: identity

我正在尝试更新系统中的记录。模型上的所有内容都保存得很好,除了我在表单上的多对多类型关系中的任何一个。当我到达我的模型中的那些时,它给了我错误。 "The member with identity 'PmData.SafetyRequirement_Assets' does not exist in the metadata collection.\r\nParameter name: identity"。我已经阅读了其他一些答案,但我的数据库上没有任何触发器,并且我已经根据其他建议对我的模型进行了一些更改,但它似乎没有任何改变。该项目在 vNext.

这是我的第一个模型

public partial class Asset : DataModel
{
    [Required]
    [StringLength(64)]
    public string Name { get; set; }
    [StringLength(256)]
    public string Description { get; set; }
    [StringLength(1024)]
    public string SystemFunction { get; set; }
    [StringLength(2048)]
    public string Remarks { get; set; }
    public bool IsSystem { get; set; }
    public bool IsGrouping { get; set; }
    [StringLength(128)]
    public string FieldTag { get; set; }
    [ForeignKey("Parent")]
    public int? ParentId { get; set; }
    [ForeignKey("Building")]
    public int? BuildingId { get; set; }
    public bool IsOperable { get; set; }
    public bool IsAvailable { get; set; }
    public virtual Asset Parent { get; set; }
    public virtual Building Building { get; set; }
    public virtual ICollection<Asset> Children { get; set; }
    public virtual ICollection<DrawingReference> DrawingReferences { get; set; }
    public virtual ICollection<SpecReference> SpecReferences { get; set; }
    public virtual ICollection<SafetyRequirement> SafetyRequirements { get; set; }
    public virtual ICollection<SupportSystem> SupportSystems { get; set; }
}

一对多的模型table。

public partial class SafetyRequirement : DataModel
    {
        [StringLength(256)]
        [Required]
        public string Name { get; set; }
        [StringLength(2048)]
        public string SafetyFunction { get; set; }
        [StringLength(2048)]
        public string FunctionalRequirements { get; set; }
        [StringLength(2048)]
        public string SystemBoundary { get; set; }
        [StringLength(255)]
        public string Reference { get; set; }
        [ForeignKey("QualityLevel")]
        public int QualityLevelId { get; set; }
        public virtual QualityLevel QualityLevel { get; set; }
        public virtual ICollection<Asset> Assets { get; set; }
    }

加盟地图table

modelBuilder.Entity<Asset>().HasMany(t => t.SafetyRequirements)
    .WithMany(t => t.Assets)
    .Map(m =>
    {
       m.MapRightKey("SafetyRequirementId");
       m.MapLeftKey("AssetId");
       m.ToTable("AssetSafetyRequirement");
    });

最后是失败的地方...

public virtual void SaveAsync(TEntity model)
{
    Task.Run(() =>
    {
        using (
            var dbContext =
                (TContext)
                Activator.CreateInstance(typeof (TContext),
                ConfigOptions == null ? ConfigService.ConnectionString : ConfigOptions.ConnectionString))
        {
            var dbSet = dbContext.Set<TEntity>();
            dbSet.Attach(model);
            dbContext.Entry(model).State = EntityState.Modified;
            dbContext.SaveChanges();
        }
    });
}

如有任何信息或指点,我们将不胜感激。

您正在尝试使用 Fluent API 和数据注释来定义表之间的关系。删除一个或另一个。