概念类型中的成员数不匹配



我首先将实体框架代码与 dotConnect for MySQL 一起使用,由于某种原因,我收到有关我的一个模型映射的错误。

我已经搜索了此错误,它通常是由错误的xml文件或实体框架特定文件引起的。我没有使用其中任何一个,只有一个带有模型的.cs代码文件。

异常详情:

System.Data.MappingException:概念中的成员数 类型"SiteModels.TournamentTable"与 对象端的成员键入"SiteModels.TournamentTable"。做 确保成员数量相同。

我不知道为什么会出现此错误,因为我没有任何设计师,只有一个包含代码的文件。

这是有问题的类:

public class TournamentTable
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
public List<TournamentColumn> Columns { get; set; }
public TournamentTable()
{
    Columns = new List<TournamentColumn>();
}
public void AddColumn(int index, TournamentColumn column)
{
    Columns.Insert(index, column);
}
public void RemoveColumn(int index)
{
    Columns.RemoveAt(index);
}
/// <summary>
/// Add a tournament cell at the top of the column.
/// </summary>
/// <param name="column"></param>
public void AddColumn(TournamentColumn column)
{
    Columns.Add(column);
}
/// <summary>
/// Returns the tournament column at the index specified.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public TournamentColumn this[int index]
{
    get { return Columns[index]; }
}
/// <summary>
/// Returns the tournament cell at the index specified.
/// </summary>
/// <param name="columnIndex"></param>
/// <param name="cellIndex"></param>
/// <returns></returns>
public TournamentCell this[int columnIndex, int cellIndex]
{
    get { return Columns[columnIndex][cellIndex]; }
    set
    {
        Columns[columnIndex][cellIndex] = value;
    }
}

}

上下文配置:

public class EntitiesContext : DbContext
{
    public EntitiesContext()
        : base()
    {
        System.Data.Entity.Database.SetInitializer<EntitiesContext>(new DropCreateDatabaseIfModelChanges<EntitiesContext>());
    }
public EntitiesContext(DbConnection connection)
    : base(connection, true)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Conventions
      .Remove<System.Data.Entity.ModelConfiguration.Conventions
        .ColumnTypeCasingConvention>();
}
public DbSet<User> Users { get; set; }
public DbSet<Player> Players { get; set; }
public DbSet<Game> Games { get; set; }
public DbSet<TournamentTable> TournamentTables { get; set; }

}

感谢您的帮助,我没有任何线索。

尝试注释掉索引器,看看是否有帮助。如果是这样,您可能需要将 NotMapped 属性放在它们上或将它们重新实现为方法。

最新更新