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

标签 mysql entity-framework devart dotconnect

我首先将 Entity Framework 代码与 dotConnect for MySQL 结合使用,但出于某种原因,我收到有关我的模型映射之一的错误。

我搜索过这个错误,它通常是由错误的 xml 文件或特定于 Entity Framework 的文件引起的。我没有使用其中的任何一个,只有一个带有模型的 .cs 代码文件。

异常详情:

System.Data.MappingException: The number of members in the conceptual type 'SiteModels.TournamentTable' does not match with the number of members on the object side type 'SiteModels.TournamentTable'. Make sure the number of members are the same.

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

这是有问题的类:

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 属性放在它们上或将它们重新实现为方法。

关于mysql - 概念类型中的成员数不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12608868/

相关文章:

c# - Entity Framework : SELECT From Where ID NOT IN

oracle - Oracle 连接字符串上的 Unicode 参数

php - 在具有 SELECT DISTINCT from($result) WHERE, ?possible 形式的后续查询中重用 MySQL 结果

mysql - 将子子项中的外键添加到 "super parent"- 是否有更好的方法如 View ?

c# - 如何让 Entity Framework 在 1 :1 relationship? 上执行联接查询

c# - 在主表中创建具有重命名字段和非主键的实体关系

sql-server - Delphi:使用参数时如何获取传递到服务器的查询

c# - Entity Framework 6 无法识别数据库模型中的映射函数

php - 如果不存在则创建一个 mysql 记录,否则更新它

java - 如何在Java程序中执行MySQL查询 "show tables;"..?