【问题标题】:how do i resolve this error?There is no argument given that corresponds to the required formal parameter我该如何解决这个错误?没有给出与所需形式参数相对应的参数
【发布时间】:2019-07-22 12:22:41
【问题描述】:

我有这个代码:

namespace Nop.Plugin.MostViewed
{
    public class MostViewCustom : BasePlugin, IWidgetPlugin
    {
        private readonly MVPObjectContext _context;

        public MostViewCustom(MVPObjectContext context)
        {
            this._context = context;
        }
    }
}

它给了我以下错误:

Error CS7036 There is no argument given that corresponds to the required formal parameter 'nameOrConnectionString' of 'BasePlugin.BasePlugin(string)' Nop.Plugin.MostViewed

代码有什么问题?

【问题讨论】:

    标签: c# plugins nopcommerce


    【解决方案1】:

    你需要调用基础构造函数,像这样:

    const string nameOrConnectionString = "???";
    public MostViewCustom(MVPObjectContext context)
        : base(nameOrConnectionString) // <-- magic here
    {
        this._context = context;
    }
    

    下次,请将您的代码放在问题中的代码块中,这样更容易为您提供帮助。

    【讨论】:

    • 我已经写了这个 public MostViewCustom(MVPObjectContext context) : base(nameOrConnectionString) in MVPObjectContext class
    • @KishanHirpara 应该这样做吗?
    【解决方案2】:

    如果您使用 nopCommerce,则需要两个插件类。

    1. DbContext 类
    2. 插件类

    MostViewObjectContext.cs

    namespace Nop.Plugin.MostViewed
    {
      public class MostViewObjectContext: DbContext, IDbContext
      {
        public MostViewObjectContext(string nameOrConnectionString) : base(nameOrConnectionString) { }
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
         Database.SetInitializer<MostViewObjectContext>(null);
         modelBuilder.Configurations.Add(new YourTableMappingClass());
        }
        public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity
        {
            return base.Set<TEntity>();
        }
    
        public IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new()
        {
            throw new NotImplementedException();
        }
         public string CreateDatabaseScript()
        {
            return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
        }
        //Other all methods like  Install() and Uninstall()
      }
    }
    

    MostViewPlugin.cs

    namespace Nop.Plugin.MostViewed
    {
         public class MostViewedPlugin : BasePlugin, IWidgetPlugin
         {
          // Write code for IList<string> GetWidgetZones(),GetConfigurationPageUrl(), GetPublicViewComponent(string widgetZone, out string viewComponentName), Install() and Uninstall()
         }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-10
      • 2017-07-18
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      相关资源
      最近更新 更多