我使用的是nopCommerce 3.50。我已经在nopCommerce中实现了插件。我已经在SQL服务器中创建了存储过程。现在我想通过代码从插件中创建存储过程。当插件被安装后,它将创建存储过程。
我如何在nopCommerce中通过插件创建存储过程?
参考股票插件Nop.Plugin.Shipping.ByWeight。
你的ObjectContext会有一个Install()方法,用它来创建你的存储过程。 在Uninstall方法中删除它。
public string CreateDatabaseScript()
{
return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
}
/// <summary>
/// Install
/// </summary>
public void Install()
{
//create the table
var dbScript = CreateDatabaseScript();
Database.ExecuteSqlCommand(dbScript);
SaveChanges();
}
/// <summary>
/// Uninstall
/// </summary>
public void Uninstall()
{
//drop the table
var tableName = this.GetTableName<ShippingByWeightRecord>();
//var tableName = "ShippingByWeight";
this.DropPluginTable(tableName);
}
参考 Nop.Service.CAtalog.ProductService
var products = _dbContext.ExecuteStoredProcedureList<Product>(
"ProductLoadAllPaged",
pCategoryIds,
pManufacturerId,
pStoreId,
pVendorId,
pWarehouseId,
pParentGroupedProductId,
pProductTypeId,
pVisibleIndividuallyOnly,
pProductTagId,
pFeaturedProducts,
pPriceMin,
pPriceMax,
pKeywords,
pSearchDescriptions,
pSearchSku,
pSearchProductTags,
pUseFullTextSearch,
pFullTextMode,
pFilteredSpecs,
pLanguageId,
pOrderBy,
pAllowedCustomerRoleIds,
pPageIndex,
pPageSize,
pShowHidden,
pLoadFilterableSpecificationAttributeOptionIds,
pFilterableSpecificationAttributeOptionIds,
pTotalRecords);
它呼吁 productloadallpaged
存储过程。
这样就可以了。
public class SearchEngineData : ISearchEngineData
{
private readonly IDbContext _dbContext;
public SearchEngineData(IDbContext dbContext){
_dbContext = dbContext;
}
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();
}
}