The entity type PromoSliderRecord is not part of the model for the current context.
I keep getting this issue when my post back trys to run this in my controller.
[HttpPost]
public ActionResult CreateUpdatePromoSlider(PromoSliderRecord record)
{
if (ModelState.IsValid)
{
PromoSliderRecord slider = _sliderRepo.GetById(record.PromoSliderId);
...
here is my object
public class PromoSliderRecord : BaseEntity
{
public PromoSliderRecord()
{
Images = new List<PromoImageRecord>();
}
public virtual int PromoSliderId { get; set; }
public virtual string PromoSliderName { get; set; }
public bool IsActive { get; set; }
public bool IsParallax { get; set; }
public virtual string ZoneName { get; set; }
public virtual int Interval { get; set; }
public virtual bool PauseOnHover { get; set; }
public virtual bool Wrap { get; set; }
public virtual bool KeyBoard { get; set; }
public virtual List<PromoImageRecord> Images { get; set; }
}
here is my map
using Nop.Plugin.Widgets.PromoSlider.Domain;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nop.Plugin.Widgets.PromoSlider.Data
{
public class PromoSliderMap : EntityTypeConfiguration<PromoSliderRecord>
{
public PromoSliderMap()
{
ToTable("PromoSlider_PromoSliders");
HasKey(m => m.PromoSliderId);
Property(m => m.PromoSliderName);
Property(m => m.ZoneName);
Property(m => m.Interval);
Property(m => m.KeyBoard);
Property(m => m.PauseOnHover);
Property(m => m.Wrap);
}
}
}
Here is my object context class
using Nop.Data;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nop.Core;
namespace Nop.Plugin.Widgets.PromoSlider.Data
{
public class PromoSliderObjectContext : DbContext, IDbContext
{
public bool ProxyCreationEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public bool AutoDetectChangesEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public PromoSliderObjectContext(string nameOrConnectionString) : base(nameOrConnectionString){}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new PromoSliderMap());
modelBuilder.Configurations.Add(new PromoImageMap());
base.OnModelCreating(modelBuilder);
}
public string CreateDatabaseInstallationScript()
{
return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
}
public void Install()
{
Database.SetInitializer<PromoSliderObjectContext>(null);
Database.ExecuteSqlCommand(CreateDatabaseInstallationScript());
SaveChanges();
}
public void UnInstall()
{
this.DropPluginTable("PromoSlider_PromoImages");
this.DropPluginTable("PromoSlider_PromoSliders");
}
public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity
{
return base.Set<TEntity>();
}
public IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new()
{
throw new NotImplementedException();
}
public IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters)
{
throw new NotImplementedException();
}
public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = default(int?), params object[] parameters)
{
throw new NotImplementedException();
}
public void Detach(object entity)
{
throw new NotImplementedException();
}
}
}
here is my dependency registrar
using Nop.Core.Data;
using Autofac.Core;
namespace Nop.Plugin.Widgets.PromoSlider.Data
{
public class PromoSliderDependancyRegistrar : IDependencyRegistrar
{
private const string CONTEXT_NAME = "nop_object_context_promo_slider";
public int Order
{
get
{
return 1;
}
}
public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
{
this.RegisterPluginDataContext<PromoSliderObjectContext>(builder, CONTEXT_NAME);
//override required repository with our custom context
builder.RegisterType<EfRepository<PromoSliderRecord>>()
.As<IRepository<PromoSliderRecord>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME))
.InstancePerLifetimeScope();
builder.RegisterType<EfRepository<PromoImageRecord>>()
.As<IRepository<PromoImageRecord>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME))
.InstancePerLifetimeScope();
}
}
}
My tables were generated on install fine, my connection string in the settings.txt file is
DataProvider: sqlserver
DataConnectionString: Data Source=SQLSERV1\SQLSERV1;Initial Catalog=fake;User ID=fake;Password=fake
Any one know why this is happening?