尝试执行以下代码时,我收到了 InvalidOperationException “Sequence Contains No Matching Element”。这是在数据库的初始设置上:
Global.migrationContext.SourceObjects.Add(sourceObject);
源对象如下所示:
DataMigrationMapping.SourceObject
MigrationPasses null System.Collections.ObjectModel.ObservableCollection<DataMigrationMapping.MigrationPass>
Name "COMP_CASE" string
Notes "Complaint Case" string
Schema "Wacka" string
SourceElements null System.Collections.Generic.List<DataMigrationMapping.SourceElement>
SourceObjectID 0 int
我的 dbContext 看起来像这样:
public class MigrationContext : DbContext
{
public DbSet<SourceObject> SourceObjects {get; set;}
public DbSet<SourceElement> SourceElements {get; set;}
public DbSet<MigrationPass> MigrationPasses {get; set;}
public DbSet<Entity> Entities {get; set;}
public MigrationContext(string connectionString)
: base(connectionString)
{
}
public void Load()
{
SourceObjects.Load();
SourceElements.Load();
MigrationPasses.Load();
Entities.Load();
}
}
在我将此属性添加到 MigrationPass 类后,错误开始出现:
public Entity TargetEntity { get; set; }
这让我相信我的模型从 Entity 类流出有问题。可能与这个类是抽象的有关。实体类如下所示:
public abstract class Entity
{
public int EntityID { get; set; }
public string Name { get; set; }
public EntityType EntityType { get; set; }
public string RefCode { get; set; }
public Cardinality Cardinality { get; set; }
protected ObservableCollection<Field> fields;
[NotMapped]
public ObservableCollection<Field> Fields
{
get { return fields; }
}
public void AddField(Field field)
{
fields.Add(field);
}
protected ObservableCollection<Entity> roles;
[NotMapped]
public ObservableCollection<Entity> Roles
{
get { return roles; }
}
public void AddRole(Entity role)
{
roles.Add(role);
}
关于可能导致错误的任何想法?