[nopCommerce 4.2] How to execute stored procedure and get return list.?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
I'm using nopCommerce 4.2 and trying to get a product list. I have tried using the below code.

 var pProductIds = _dataProvider.GetStringParameter("ProductIds", productIds);
var elasticIndexProducts =
_dbContext.EntityFromSql<ProductList>("Exec SP_GetProductsForElastic @ProductIds", pProductIds).ToList();


But I'm getting an error saying "Cannot create a DbSet for 'ProductList' because this type is not included in the model for the context."

This my model
 public class ProductList
    {
        public DateTime IndexDate { get; set; }
        public string ProductId { get; set; }
        public string PartNumber { get; set; }
        public string Name { get; set; }
        public string MetaKeywords { get; set; }
        public string MetaDescription { get; set; }
        public string MetaTitle { get; set; }
        public int LimitedToStores { get; set; }
        public string ShortDescription { get; set; }
        public string FullDescription { get; set; }
        public string SeName { get; set; }
}


Please help... urgent...
3 years ago
I have mistakenly added EntityFromSql<ProductList>  instead of QueryFromSql<ProductList> for my quection. however both are getting error.

isanka.thalagala wrote:
I'm using nopCommerce 4.2 and trying to get a product list. I have tried using the below code.

 var pProductIds = _dataProvider.GetStringParameter("ProductIds", productIds);
var elasticIndexProducts =
_dbContext.QueryFromSql<ProductList>("Exec SP_GetProductsForElastic @ProductIds", pProductIds).ToList();


But I'm getting an error saying "Cannot create a DbSet for 'ProductList' because this type is not included in the model for the context."

This my model
 public class ProductList
    {
        public DateTime IndexDate { get; set; }
        public string ProductId { get; set; }
        public string PartNumber { get; set; }
        public string Name { get; set; }
        public string MetaKeywords { get; set; }
        public string MetaDescription { get; set; }
        public string MetaTitle { get; set; }
        public int LimitedToStores { get; set; }
        public string ShortDescription { get; set; }
        public string FullDescription { get; set; }
        public string SeName { get; set; }
}


Please help... urgent...
3 years ago
I have something like this
var query = "EXEC SP_GetProductsForElastic @ProductIds= '" + wherever you need to make the correctly formed query that runs in SQL
var records = _dbContext.Set<ProductList>().FromSql(query).ToList();
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.