2016-10-18 3 views
2

이것은 Nopcommerce에서 처음 데모 프로젝트이며 내 자신의 플러그인을 만들려고했지만 Build 중에는 오류가 발생했습니다. 아래는 몇 가지 코드입니다.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; } 
     } 
    } 

참고

같은 당신의 설치 방법 코드합니다 너는을 바꿔야 해.을 컨텍스트 이름에 적용하고 엔티티 클래스와 동일하게

희망이 있습니다.

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; } 
    } 
관련 문제