Stored Procedure in Nop Commerce

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 6 años
how to call stored procedure in nop commerce . When i call stored procedure in nop commerce i get this error.
The entity type TopCategoriesMapping is not part of the model for the current context.
WHY
Hace 6 años
pccplayer411 wrote:
how to call stored procedure in nop commerce . When i call stored procedure in nop commerce i get this error.
The entity type TopCategoriesMapping is not part of the model for the current context.
WHY

  public virtual IPagedList<GetTopProduct> GetProductCategoriesByCategoryId(int categoryId,
             int pageIndex = 0, int pageSize = int.MaxValue)
        {
            if (categoryId == 0)
                return new PagedList<GetTopProduct>(new List<GetTopProduct>(), pageIndex, pageSize);


            int totalCount = 0;
            var pCategoryIds = _dataProvider.GetParameter();
            pCategoryIds.ParameterName = "CategoryId";
            pCategoryIds.Value = categoryId;
            pCategoryIds.DbType = DbType.Int32;

            var pPageIndex = _dataProvider.GetParameter();
            pPageIndex.ParameterName = "PageIndex";
            pPageIndex.Value = pageIndex;
            pPageIndex.DbType = DbType.Int32;

            var pPageSize = _dataProvider.GetParameter();
            pPageSize.ParameterName = "PageSize";
            pPageSize.Value = pageSize;
            pPageSize.DbType = DbType.Int32;

            var product = _dbContext.ExecuteStoredProcedureList<GetTopProduct>("GetProductByTopCategoryId", pCategoryIds,pPageIndex,pPageSize);
            //var query = from tcm in _topCategoriesMappingRepository.Table
            //            join p in _productRepo.Table on tcm.ProductId equals p.Id
            //            where tcm.TopCategoriesId == categoryId &&
            //                      !p.Deleted &&
            //                      (showHidden || p.Published)
            //            select tcm ;
            if (product != null && product.Count > 0)
                totalCount = product.ToList().FirstOrDefault().TotalCount;


            return new PagedList<GetTopProduct>(product, pageIndex, pageSize,totalCount);
        }

Hace 6 años
Hello,

Are you doing this code in plugin?

And did you added your custom class TopCategoriesMapping in Dependency file ? Like below code

  builder.RegisterType<EfRepository<TopCategoriesMapping>>()
                .As<IRepository<TopCategoriesMapping>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_CategoriesMapping"))
                .InstancePerLifetimeScope();


Thanks,
Jatin
Hace 6 años
Yup this code already apply at my Object Context but its also meet the same problem
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.