Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

“The entity type AppPlatformViewModel is not a part of the current context”

I am using Multi-View Model to save data in database.

CreateAppViewModel

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

    namespace MobiTest.Models
    {
       [Table("UserApps")]
        public class CreateAppViewModel
        {

            public int UserID { get; set; }
            public int PlatformID { get; set; }

            public string AppName { get; set; }


        }
    }

PlatformViewModel

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

namespace MobiTest.Models
{
    [Table("PlatformViewModels")]
    public class PlatformViewModel
    {

        public int PlatformID { get; set; }


    }
}

AppPlatformMultiView (MultiView)

namespace MobiTest.Models
{
    public class AppPlatformMultiView
    {
        public CreateAppViewModel CreateAppViewModels { get; set; }
        public PlatformViewModel PlatformViewModels { get; set; }

    }
}

Home Controller

 public ActionResult CreateApp(AppPlatformMultiView obj)
        {

            if (ModelState.IsValid)
            {
                db.CreateAppViewModels.Add(obj.CreateAppViewModels);
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            else
            {
                TempData["msg"] = "Please enter all the credentials";
            }
            return View(obj.CreateAppViewModels);
        }
    }

DbContext class

public partial class MobiTestEntities : DbContext
    {
        public MobiTestEntities()
            : base("name=MobiTestEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CreateAppViewModel>().ToTable("UserApps");

        }

   public virtual DbSet<CreateAppViewModel> CreateAppViewModels { get; set; }
   public virtual DbSet<PlatformViewModel> PlatformViewModels { get; set; }

        public virtual DbSet<Platform> Platforms { get; set; }

I get error at.... saying "The entity CreateAppViewModel is not a part of the current context

db.CreateAppViewModels.Add(obj.CreateAppViewModels);

Please Help, I am using Entity Framework in ASP.NET MVC I am new to coding, have tried every possible code to resolve the error.

Comments