简体   繁体   中英

Nop Commerce - Map custom stored procedure to Entity

I am using nop commerce 3.4, (it uses EF - Code First) and I would like to map a stored procedure that executes a select, to a custom entity.
I have created the custom entity (CategoryItemModel) to map to in the Domain. But when NopObjectContext runs calling the stored proc i get the error:
The entity type CategoryItemModel is not part of the model for the current context. How do I add my CategoryItemModel to the context?
Thanks in advance.

Have you written the mapping? Here's an example of a mapping for Product entity.

using System.Data.Entity.ModelConfiguration;
using Nop.Core.Domain.Catalog;

namespace Nop.Data.Mapping.Catalog
{
    public partial class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            this.ToTable("Product");
            this.HasKey(p => p.Id);
            this.Property(p => p.Name).IsRequired().HasMaxLength(400);
            this.Property(p => p.MetaKeywords).HasMaxLength(400);

            /* ... other mappings ... */
            /* ... refer 'Product.cs' ... */
        }
    }
}

I think you expected solution like below, I know it's late. But I added this for future references.

This only works nopCommers < 4.0

private List<ElasticStoreMapping> GetStoreMappingsForProducts(int[] productIds)
{
   var pProductIds = _dataProvider.GetParameter();
   pProductIds.ParameterName = "ProductIds";
   pProductIds.Value = productIds == null ? string.Empty : string.Join(",", productIds);
   pProductIds.DbType = DbType.String;

   return _dbContext.SqlQuery<ElasticStoreMapping>($"Exec GetStoreMappingForElastic @ProductIds", pProductIds).ToList();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM