Question

I am using entity framework code first with dotConnect for MySQL, and for some reason I get an error about one of my models mapping.

I've searched this error and it is usually caused by bad xml file or entity framework specific files. I am not using any of these, only a .cs code file with the models.

Exception Details:

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.

I have no idea why I am getting this error, since I don't have any designer, only one file containing the code.

Here is the problematic class:

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;
    }
}

}

Context configuration:

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; }

}

Thanks for the help, I don't have any clue.

Was it helpful?

Solution

Try commenting out the indexers and see if it helps. If it does you may need to put NotMapped attribute on them or reimplement them as methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top