2016-10-18 4 views
2

これはNopcommerceの初めてのデモプロジェクトです。自分のプラグインを作成しようとしましたが、ビルド時にエラーが発生しました。以下はいくつかのコードです。Nop Commerceにプラグインを作成中にエラーが発生しました

namespace Nop.Plugin.Aowi.Testimonial.Data 
{ 
    public class TestimonialRecordObjectContext : DbContext , IDbContext 
    { 
    public TestimonialRecordObjectContext(string nameOrConnectionString) : base(nameOrConnectionString) { } 

    #region Implementation of IDbContext 

    #endregion 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     modelBuilder.Configurations.Add(new TestimonialRecordMap()); 
     base.OnModelCreating(modelBuilder); 
    } 

    public string CreateDatabaseInstallationScript() 
    { 
     return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript(); 
    } 

    public void Install() 
    { 
     //It's required to set initializer to null (for SQL Server Compact). 
     //otherwise, you'll get something like "The model backing the 'your context name' context has changed since the database was created. Consider using Code First Migrations to update the database" 


    Database.SetInitializer<TestimonialRecordObjectContext>(null); 
      Database.ExecuteSqlCommand(CreateDatabaseInstallationScript()); 
      SaveChanges(); 
     } 

     public void Uninstall() 
     { 
      var dbScript = "DROP TABLE Testimonial"; 
      Database.ExecuteSqlCommand(dbScript); 
      SaveChanges(); 
     } 

     public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity 
     { 
      return base.Set<TEntity>(); 
     } 

     public System.Collections.Generic.IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new() 
     { 
      throw new System.NotImplementedException(); 
     } 

     public System.Collections.Generic.IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters) 
     { 
      throw new System.NotImplementedException(); 
     } 

     public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters) 
     { 
      throw new System.NotImplementedException(); 
     } 
    } 
} 

これは、でも私は、このエラーを取得しています清掃やビルの後に依存レジストラ一部

namespace Nop.Plugin.Aowi.Testimonial.Infastructure 
{ 
    public class DependencyRegistrar: IDependencyRegistrar 
    { 
     private const string CONTEXT_NAME ="nop_object_context_product_view_tracker"; 

    public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config) 
    { 


     //data context 
     this.RegisterPluginDataContext<TestimonialRecordObjectContext>(builder, CONTEXT_NAME); 

     //override required repository with our custom context 
     builder.RegisterType<EfRepository<TestimonialRecord>>() 
      .As<IRepository<TestimonialRecord>>() 
      .WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME)) 
      .InstancePerLifetimeScope(); 
    } 

    public int Order 
    { 
     get { return 1; } 
    } 
} 
} 

です。 enter image description here

誰でも私にこれを手伝ってもらえますか?私はチュートリアルを見てこのことをすべてやったので、誰かが私のミスを訂正するのを助けることができれば、本当に素晴らしいことになるでしょう。

+0

ありません、それはまだ同じエラーが表示されます。 – Avinash

答えて

1

実際の問題がどこにあるかをコードから知ることはできません。しかし、私は例で示唆しています。

のようなあなたのインストール方法のコード作成:

public void Install() 
{ 
    //create the table 
    var dbScript = CreateDatabaseScript(); 
    Database.ExecuteSqlCommand(dbScript); 
    SaveChanges(); 
} 

EfStartUpTaskと呼ばれる新しいクラスを追加し、次のコードを貼り付けます:

public class EfStartUpTask : IStartupTask 
    { 
     public void Execute() 
     { 
      //It's required to set initializer to null (for SQL Server Compact). 
      //otherwise, you'll get something like "The model backing the 'your context name' context has changed since the database was created. Consider using Code First Migrations to update the database" 
      Database.SetInitializer<YourContext>(null); 
     } 

     public int Order 
     { 
      //ensure that this task is run first 
      get { return 0; } 
     } 
    } 

そして、あなたのDependencyRegistrar

public class DependencyRegistrar : IDependencyRegistrar 
{ 
     public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder) 
     { 
      builder.RegisterType<YourService>().As<YourserviceInterface>().InstancePerLifetimeScope(); 

      //data context 
      this.RegisterPluginDataContext<YourContext>(builder, "nop_object_context_product_view_tracker"); 

      //override required repository with our custom context 
      builder.RegisterType<EfRepository<YourEntityClass>>() 
       .As<IRepository<YourEntityClass>>() 
       .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_product_view_tracker")) 
       .InstancePerLifetimeScope(); 
     } 

     public int Order 
     { 
      get { return 1; } 
     } 
    } 

注:変更する必要がありますYourContextをあなたのコンテクスト名に、エンティティクラスと同じにしてください

これは役に立ちます。

2

エラーログに記述されているIDbContextインターフェイスのこのメソッドとプロパティをカスタムコンテキストで実装するだけで済みます。それは既存のプラグインTax.CountryStateZipのいずれかで行われている方法例えば

、:

public void Detach(object entity) 
    { 
     if (entity == null) 
      throw new ArgumentNullException("entity"); 

     ((IObjectContextAdapter)this).ObjectContext.Detach(entity); 
    } 

    public virtual bool ProxyCreationEnabled 
    { 
     get { return this.Configuration.ProxyCreationEnabled; } 
     set { this.Configuration.ProxyCreationEnabled = value; } 
    } 

    public virtual bool AutoDetectChangesEnabled 
    { 
     get { return this.Configuration.AutoDetectChangesEnabled; } 
     set { this.Configuration.AutoDetectChangesEnabled = value; } 
    } 
関連する問題