我正在使用nopCommerce 3.50。我在nopCommerce中实现了插件。我在SQL服务器中创建了存储过程。现在我想通过代码从插件创建存储过程。安装插件时,它将创建存储过程。
如何在nopCommerce中从插件创建存储过程?
答案 0 :(得分:1)
请参阅股票插件Nop.Plugin.Shipping.ByWeight
您的ObjectContext将具有Install()方法,用于创建存储过程。在卸载方法中删除它。
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);
}
答案 1 :(得分:0)
请参阅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
存储过程。
答案 2 :(得分:0)
这将起作用。
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();
}
}