我正在使用nop commerce 3.4,(它使用EF - Code First),我想将一个执行选择的存储过程映射到一个自定义实体。我已经在域中创建了自定义实体(CategoryItemModel)来映射。The entity type CategoryItemModel is not part of the model for the current context.How do I add my CategoryItemModel to the context? 先谢谢你。
你写过映射吗?这里有一个产品实体映射的例子。
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' ... */
}
}
}
我想你期望的解决方案就像下面一样,我知道这已经晚了。但我添加了这个,以备将来参考。
这只适用于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();
}