“The entity type <model> is not part of the model for the current context.”

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi,

I created 3 tables, this tables represent attributes in the customer (In this case Im gonna write about one), I created the Interface and the classes, I passed the service to the constructor and fill the values in a ViewBag.

The problem Im having is  “The entity type <model> is not part of the model for the current context.”

This is my service:
using Blah.Service.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Blah.Data.DTO;
using Nop.Data;
using Nop.Core.Data;

namespace Blah.Service
{   /// <summary>
    ///  Servicio que trae las direccion del customer
    ///  Y tambien proporciona listas de provincia,municipio y localidad
    /// </summary>
    public class DireccionService : IDireccionService
    {

        #region Fields
        private readonly IRepository<Localidad> _localidadRepository;
        private readonly IRepository<Provincia> _ProvinciaRepository;
        private readonly IRepository<Municipio> _MunicipioRepository;
        private readonly IRepository<Direccion> _DireccionRepository;
        private readonly IDataProvider _dataProvider;
        private readonly IDbContext _dbContext;

        #endregion

        #region Ctor
        public DireccionService(

            IRepository<Localidad> localidadRepository,
            IRepository<Provincia> ProvinciaRepository,
            IRepository<Municipio> MunicipioRepository,
            IRepository<Direccion> DireccionRepository,
            IDataProvider dataProvider,
            IDbContext dbContext
            )
        {
            this._localidadRepository = localidadRepository;
            this._ProvinciaRepository = ProvinciaRepository;
            this._MunicipioRepository = MunicipioRepository;
            this._DireccionRepository = DireccionRepository;
            this._dataProvider = dataProvider;
            this._dbContext = dbContext;

        }

        #endregion

        #region Public Methods
        /// <summary>
        /// Obtiene la direccion de un Customer por id
        /// </summary>
        /// <param name="CustomerDirecionID">Id del customer</param>
        /// <returns></returns>
        public Direccion GetCustomerDireccion(int CustomerDireccionID)
        {
            try
            {
                var query = _DireccionRepository.Table;

                return query.Where(x => x.Id == CustomerDireccionID)
                                                .FirstOrDefault();
            }
            catch (Exception)
            {
                return null;
            }

        }

        /// <summary>
        /// Obtiene las localidades por municipio
        /// </summary>
        /// <returns></returns>
        public List<Localidad> GetLocalidades(int MunicipioID)
        {
            try
            {
                var query = _localidadRepository.Table;

                return query.Where(p => p.MunicipioId == MunicipioID)
                                              .ToList<Localidad>();
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// Obtiene los municipios por provincia
        /// </summary>
        /// <returns></returns>
        public List<Municipio> GetMunicipios(int ProvinciaID)
        {
            try
            {
                var query = _MunicipioRepository.Table;

                return query.Where(p => p.ProvinciaId == ProvinciaID)
                                              .ToList<Municipio>();
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// Obtiene todas las provincias
        /// </summary>
        /// <returns></returns>
        public List<Provincia> GetProvincias()
        {
            try
            {
                var query = _ProvinciaRepository.TableNoTracking;

                List<Provincia> listProvincias = new List<Provincia>();

                listProvincias = query.ToList<Provincia>();

                return listProvincias;
            }
            catch (Exception ex)
            {
                return new List<Provincia>();
            }

        }

        #endregion  

    }
}


This is my Interface:
using Blah.Data.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blah.Service.Interfaces
{
    public interface IDireccionService
    {
        List<Provincia> GetProvincias();

        List<Municipio> GetMunicipios(int ProvinciaID);

        List<Localidad> GetLocalidades(int MunicipioID);

        Direccion GetCustomerDireccion(int CustomerDireccionID);
    }
}


This is one of my domain class:
using Nop.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blah.Data.DTO
{
    public class Provincia : BaseEntity
    {
        public int ProvinciaID { get; set; }
        public string Nombre { get; set; }
    }
}


I added the service to the Ctor, fields on my CustomerController.
In My constructor the part that fails is in the Register() Method at this part:
ViewBag.Provincias = _MyService.GetProvincias();


And in my DependencyRegistrar in Framework I have the following:
// Registrar Servicio de direccion de customer
builder.RegisterType<Jumbo.DireccionService>().As<IDireccionService>().InstancePerLifetimeScope();

[u][/u]
6 years ago
Go through ==>Nop.Plugin.Feed.GoogleShopping

1. you have to create an ObjectContext
2. you have to register your ObjectContext and also your Repository too
6 years ago
sohel wrote:
Go through ==>Nop.Plugin.Feed.GoogleShopping

1. you have to create an ObjectContext
2. you have to register your ObjectContext and also your Repository too


GoogleShopping? Why this plugin?
6 years ago
Nickso wrote:
Go through ==>Nop.Plugin.Feed.GoogleShopping

1. you have to create an ObjectContext
2. you have to register your ObjectContext and also your Repository too

GoogleShopping? Why this plugin?



If you go through this plugin you will know, how to create a plugin with new table. And you able to find where you did wrong.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.