I'm having trouble mapping/updating my database in my MVC project with any ArrayList fields. When I have [NotMapped] over any instances of ArrayList fields in my models files, any model changes are successfully migrated. Is this how you implement tables with Array fields? Or is there another way?

Here are the errors I'm getting:

In the Package Manager Console:

PM> Add-Migration ArrayListFields
System.ArgumentNullException: Value cannot be null.
Parameter name: entitySet
   at System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
   at System.Data.Entity.Core.Mapping.EntitySetMapping..ctor(EntitySet entitySet, EntityContainerMapping containerMapping)
   at System.Data.Entity.ModelConfiguration.Edm.DbDatabaseMappingExtensions.AddEntitySetMapping(DbDatabaseMapping databaseMapping, EntitySet entitySet)
   at System.Data.Entity.ModelConfiguration.Edm.Services.TableMappingGenerator.Generate(EntityType entityType, DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel conceptualModel)
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
   at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
   at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
   at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml)
   at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Value cannot be null.
Parameter name: entitySet

The 2 Model files with ArrayList:

ProfileMeta.cs:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace DatingSiteAttempt2.Models
{
    public class ProfileMeta
    {
        [Key, ForeignKey("ProfileDetail")]
        public int ID { get; set; }
        public string Username { get; set; }
        public string password { get; set; }

        //Dynamic Array
        //[NotMapped]
        public ArrayList ConversationMetaID { get; set; }
        public int ProfileDetailID { get; set; }

        public virtual ProfileDetail ProfileDetail { get; set; }
        public virtual ICollection<MessageDetail> MessageDetails { get; set; }
        public virtual ICollection<ConversationMeta> ConversationMetas { get; set; }
    }
}


ConversationMeta.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace DatingSiteAttempt2.Models
{
    public class ConversationMeta
    {
        public int ID { get; set; }

        //Dynamic Array: All messages for a given conversation/msg thread
        //[NotMapped]
        public ArrayList MessageDetailsID { get; set; }

        //Responder/Initiator IDs are ProfileMeta IDs
        public int InitiatorID { get; set; }
        public int ResponderID { get; set; }

        public virtual ICollection<MessageDetail> MessageDetails { get; set; }
        public virtual ICollection<ProfileMeta> ProfileMetas { get; set; }
    }
}

Context File:

DAL/DatingSiteContext.cs

using DatingSiteAttempt2.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;

namespace DatingSiteAttempt2.DAL
{
    public class DatingSiteContext : DbContext
    {
        public DatingSiteContext() : base("DatingSiteContext") { }

        public DbSet<ProfileMeta> ProfileMetas { get; set; }
        public DbSet<ProfileDetail> ProfileDetails { get; set; }
        public DbSet<ConversationMeta> ConversationMetas { get; set; }
        public DbSet<MessageDetail> MessageDetails { get; set; }


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //Disable/Remove pluralizing of table names in DB
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }
}

Related posts

Recent Viewed