Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Found more than one concrete type for given DbContext Type #1184


User avatar
0
sampath created

Hi, I have updated to latest version. But when I was trying to run, it gave this error. Can you tell me why ? Thanks.

{"Found more than one concrete type for given DbContext Type (Abp.Zero.EntityFramework.AbpZeroCommonDbContext`2[IP.Authorization.Roles.Role,IP.Authorization.Users.User]) but none of them defines MultiTenancySideAttribute with Host"}

Stack trace : I don't know from where this is coming.I don't have such folder on my machine. "D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\DefaultDbContextResolver.cs"

at Abp.EntityFramework.DbContextTypeMatcher.GetConcreteType(Type dbContextType) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\DbContextTypeMatcher.cs:line 79
   at Abp.EntityFramework.DefaultDbContextResolver.Resolve[TDbContext](String connectionString) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\DefaultDbContextResolver.cs:line 29
   at Abp.EntityFramework.Uow.EfUnitOfWork.GetOrCreateDbContext[TDbContext](Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 146
   at Abp.EntityFramework.Uow.UnitOfWorkExtensions.GetDbContext[TDbContext](IActiveUnitOfWork unitOfWork, Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\UnitOfWorkExtensions.cs:line 38
   at Abp.EntityFramework.Uow.UnitOfWorkDbContextProvider`1.GetDbContext(Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\UnitOfWorkDbContextProvider.cs:line 38
   at Castle.Proxies.EfRepositoryBase`2Proxy.get_Context_callback()
   at Castle.Proxies.Invocations.EfRepositoryBase`3_get_Context.InvokeMethodOnTarget()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 53
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 45
   at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 35
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.EfRepositoryBase`2Proxy.get_Context()
   at Abp.EntityFramework.Repositories.EfRepositoryBase`3.get_Table() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 30
   at Castle.Proxies.EfRepositoryBase`2Proxy.get_Table_callback()
   at Castle.Proxies.Invocations.EfRepositoryBase`3_get_Table.InvokeMethodOnTarget()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 53
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 45
   at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 35
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.EfRepositoryBase`2Proxy.get_Table()
   at Castle.Proxies.EfRepositoryBase`2Proxy.GetAll_callback()
   at Castle.Proxies.Invocations.EfRepositoryBase`3_GetAll.InvokeMethodOnTarget()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 53
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 45
   at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 35
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.EfRepositoryBase`2Proxy.GetAll()
   at Abp.EntityFramework.Repositories.EfRepositoryBase`3.<GetAllListAsync>d__7.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Threading.InternalAsyncHelper.&lt;AwaitTaskWithPostActionAndFinallyAndGetResult&gt;d__5`1.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:line 120
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Localization.ApplicationLanguageManager.&lt;GetLanguagesFromDatabaseAsync&gt;d__17.MoveNext() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Localization\ApplicationLanguageManager.cs:line 204
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:line 120
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Runtime.Caching.CacheExtensions.<>c__DisplayClass5_0`2.&lt;&lt;GetAsync&gt;b__0>d.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:line 40
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Runtime.Caching.CacheBase.<GetAsync>d__12.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheBase.cs:line 67
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Runtime.Caching.CacheExtensions.&lt;GetAsync&gt;d__5`2.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:line 38
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Localization.ApplicationLanguageManager.&lt;GetLanguageDictionary&gt;d__15.MoveNext() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Localization\ApplicationLanguageManager.cs:line 178
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Localization.ApplicationLanguageManager.<GetLanguagesAsync>d__8.MoveNext() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Localization\ApplicationLanguageManager.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
   at Nito.AsyncEx.AsyncContext.<>c__DisplayClass7`1.&lt;Run&gt;b__5(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
   at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
   at Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\AsyncHelper.cs:line 33
   at Abp.Localization.ApplicationLanguageProvider.GetLanguages() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Localization\ApplicationLanguageProvider.cs:line 35
   at Abp.Localization.LanguageManager.GetLanguages() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Localization\LanguageManager.cs:line 21
   at Abp.Localization.MultiTenantLocalizationDictionaryProvider.GetDictionaries() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Localization\MultiTenantLocalizationDictionaryProvider.cs:line 56
   at Abp.Localization.MultiTenantLocalizationDictionaryProvider.get_Dictionaries() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Localization\MultiTenantLocalizationDictionaryProvider.cs:line 25
   at Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource.GetStringOrNull(String name, CultureInfo culture, Boolean tryDefaults) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Localization\Dictionaries\DictionaryBasedLocalizationSource.cs:line 84
   at Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource.GetString(String name, CultureInfo culture) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Localization\Dictionaries\DictionaryBasedLocalizationSource.cs:line 67
   at Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource.GetString(String name) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Localization\Dictionaries\DictionaryBasedLocalizationSource.cs:line 61
   at Abp.Web.Mvc.Views.AbpWebViewPage`1.L(String name) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.Web.Mvc\Web\Mvc\Views\AbpWebViewPageOfTModel.cs:line 72
   at ASP._Page_Views_Shared_Error_cshtml.Execute() in d:\VersionUpgrade\Version-1.10.1\IP.Web\Views\Shared\Error.cshtml:line 10
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.StartPage.RunPage()
   at System.Web.WebPages.StartPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

22 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    1. D:\Halil\GitHub... is my local folder which is used to package dlls. It's .NET's behaviour to write it into PDB file. This PDB is added in v0.9 to be able to debug Abp code (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Debugging">http://www.aspnetboilerplate.com/Pages/ ... /Debugging</a>)

    2. Do you have more than one DbContext classes?

  • User Avatar
    0
    sampath created

    Hi, I have 2 db contexts as shown below. But before this version upgrade, I didn't have any issue.Thanks.

  • User Avatar
    0
    hikalkan created
    Support Team

    Do both of them are derived from AbpZeroDbContext?

  • User Avatar
    0
    sampath created

    Hi,

    Yes,It is like this.

    public class IpDbContext : AbpZeroDbContext<Tenant, Role, User>
    

    and

    public class IpLegacyDbContext : AbpZeroDbContext<Tenant, Role, User>
    

    Please tell me what should I do.Thanks.

  • User Avatar
    0
    hikalkan created
    Support Team

    The problem here is that: You inject IRepository<User, long>, but how ABP can know which DbContext to use? Is one of your DbContext is just for host or you use both for tenants and host? If so, you need to use a second repository interface type. Are you doing that? If not it should not work even before ABP v0.9.

  • User Avatar
    0
    sampath created

    Hi, I do have 1 database for both tenant and host.These contexts are used for both. I'm not using second repository interface type.Can you tell me how to do that ? We're using "IpLegacyDbContext" for retrieving the Access app's data into SQL db. That is the only job of that context.It's kind of one time usage.Thanks.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I did it once for the blog example. Add AutoRepositoryTypes attribute to your legacy dbcontext like that: <a class="postlink" href="https://github.com/aspnetboilerplate/sample-blog-module/blob/master/src/Abp.Samples.Blog.EntityFramework/AbpZeroSampleDbContext.cs#L14">https://github.com/aspnetboilerplate/sa ... ext.cs#L14</a>

    This requires to define SampleBlogRepositoryBase ( <a class="postlink" href="https://github.com/aspnetboilerplate/sample-blog-module/blob/master/src/Abp.Samples.Blog.EntityFramework/Repositories/SampleBlogRepositoryBase.cs">https://github.com/aspnetboilerplate/sa ... oryBase.cs</a> ) class and ISampleBlogRepository ( <a class="postlink" href="https://github.com/aspnetboilerplate/sample-blog-module/blob/master/src/Abp.Samples.Blog.Core/Domain/Repositories/ISampleBlogRepository.cs">https://github.com/aspnetboilerplate/sa ... ository.cs</a> ) interface. You can name them for your purpose, say ILegacyRepository, no problem.

    Then, when you want to use legacydbcontext, inject ILegacyRepository<User, long>.

  • User Avatar
    0
    sampath created

    Hi, I'm sorry.Still not clear for me.Could you tell me after the above implementation how about this line ?

    public class IpLegacyDbContext : AbpZeroDbContext<Tenant, Role, User>
    

    You have mentioned about this "ILegacyRepository<User, long>".Which place do I inject this ? Thanks.

    Note : Actually this is working fine on 'version="0.8.4.0"'.I still have that copy and working fine.But anyway I have to do the changes according to the new version no.Please provide a feedback for the above query.Thanks.

  • User Avatar
    0
    sampath created

    Hi,

    1. Can you tell me which layers should I use to implement above mentioned class and interface ?

    2. If you can explain about this process or behind the scene things where it'll really help to me.Thanks.

  • User Avatar
    0
    sampath created

    Hi, I have implemented it as shown below.But it gives the same error.May be I have implemented it wrongly. Please see that.

    Note : I have tried by giving this also "IpLegacyDbContext" instead of the "IpDbContext" .But the same error.May be fundamental issue where I have implemented this. Hope you'll corrected me.

    ILegacyRepository.cs

    public interface ILegacyRepository<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
             where TEntity : class, IEntity<TPrimaryKey>
        {
    
        }
    
        public interface ILegacyRepository<TEntity> : IRepository<TEntity>
            where TEntity : class, IEntity<int>
        {
    
        }
    

    IpLegacyRepositoryBase.cs

    /// <summary>
        /// Base class for custom repositories of the application.
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <typeparam name="TPrimaryKey">Primary key type of the entity</typeparam>
        public abstract class IpLegacyRepositoryBase<TEntity, TPrimaryKey> : EfRepositoryBase<IpDbContext, TEntity, TPrimaryKey>
            where TEntity : class, IEntity<TPrimaryKey>
        {
            protected IpLegacyRepositoryBase(IDbContextProvider<IpDbContext> dbContextProvider)
                : base(dbContextProvider)
            {
    
            }
    
            //add your common methods for all repositories
        }
    
        /// <summary>
        /// Base class for custom repositories of the application.
        /// This is a shortcut of <see cref="IPRepositoryBase{TEntity,TPrimaryKey}"/> for <see cref="int"/> primary key.
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        public abstract class IpLegacyRepositoryBase<TEntity> : IpLegacyRepositoryBase<TEntity, int>
            where TEntity : class, IEntity<int>
        {
            protected IpLegacyRepositoryBase(IDbContextProvider<IpDbContext> dbContextProvider)
                : base(dbContextProvider)
            {
    
            }
    
            //do not add any method here, add to the class above (since this inherits it)!!!
        }
    

    IpLegacyDbContext.cs

    [AutoRepositoryTypes(typeof(ILegacyRepository<>), typeof(ILegacyRepository<,>), typeof(IpLegacyRepositoryBase<>), typeof(IpLegacyRepositoryBase<,>))]
        public class IpLegacyDbContext : AbpZeroDbContext<Tenant, Role, User>
        {
            public IpLegacyDbContext()
                : base("Legacy")
            {
            }
    
            public virtual DbSet<Agent> Agents { get; set; }
            public virtual DbSet<AgentContact> AgentContacts { get; set; }
    
     protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Entity<BuyerInformation>()
                    .Property(e => e.Buyerpricerangelow)
                    .HasPrecision(19, 4);
    
                modelBuilder.Entity<BuyerInformation>()
                    .Property(e => e.Buyerpricerangehigh)
                    .HasPrecision(19, 4);
    }
    }
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Your implementation seems fine. I will create a similar situation in my project and test it to see if there is a bug or configuration problem.

  • User Avatar
    0
    sampath created

    Hi, Do you have something to share it with me ? Thanks.

  • User Avatar
    0
    sampath created

    Hi, There is a "IPLegacyDataModule.cs" file also on the Entity framework layer.It's like this.

    /// <summary>
            /// Entity framework module of the application.
            /// </summary>
            [DependsOn(typeof(AbpZeroEntityFrameworkModule), typeof(IPCoreModule))]
            public class IPDataModule : AbpModule
            {
                public override void PreInitialize()
                {
                    //web.config (or app.config for non-web projects) file should containt a connection string named "Default".
                    Configuration.DefaultNameOrConnectionString = "Legacy";
                }
    
                public override void Initialize()
                {
                    IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
                }
            }
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Configuration.DefaultNameOrConnectionString is a global setting and both of your dbcontext uses it. I don't suggest to change it for your lagacy module. It should be your default connection string. If it's different for legacy dbcontext, then set in it's constructor for example.

  • User Avatar
    0
    mengvisal created
    Support Team

    Hi! I also have the problem of "Found more than one concrete type for given dbcontext type" after I upgrade from 0.8.2.0 to 0.9.3.0. Actually, I use DD design and i have many bounded contexts based on modules i have. Those bounded contexts uses only one single database or one connection string. For 0.8.2.0 version, I can do it without any problems and no need to define a custom repository since different bounded contexts contain different entities mapping and ASP.NET Zero design is smart enough to use the right bounded context. Here, i would like to confirm, for version 0.9.3.0, do i need to define each custom repository for each bounded context i have or is there anyway I can still enjoy using one repository for all bounded contexts?

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Same code should work also for v0.9.3. But since we changed it to support multiple db, we may had a mistake. Can you provide more information for your case. You may share a simplified version of your structure. Thanks.

  • User Avatar
    0
    mengvisal created
    Support Team

    Hi!

    Basically, for each module, i have a Core, Application, Mapping, and a Bounded Context (No Migration). Below are the contexts i have:

    1- Project DBContext: this project DBContext is not used as a reference in any coding projects. It is used for migrating a project as well as creating fake dbcontext in testing only. This DBContext will contain all mapping entities for a project and used to keep track a project database migration and version.

    2- Common DBContext (Bounded Context): this bounded context carries ASP Zero and those common/sharing entity mappings only. It inherits from from AbpZeroDbContext<Tenant, Role, User>. This dbcontext does not have migration .This project also contains a repository implementing IRepostory. This is referenced in ASP Zero Application, Core, Web API, and Web. This DBContext has a following static constructor:

    static CommonDbContext() { Database.SetInitializer<CommonDbContext>(null); }

    3- Module DBContext (Bounded Context) : Each module will have a dbcontext containing only entity mappings related to the module. This context is inherit from AbpDbContext. It does not have any migration file. Since each module has its own applicatoin and core project. This module bounded context does not have any repository implementation. This context is referenced in its own Core and Application projects as well as Web Api and Web project. It also has a static dbcontext:

    static ModuleADbContext() { Database.SetInitializer<ModuleADbContext>(null); }

    For these codes, It worked in the version 0.8.2.0. I only used 1 Repository implementing in CommonDataContext. For those other bounded context for each individual module no need to have the custom or extra repository. I used IRepository in all application service implementations. ASP Zero was smart enough to use the right dbcontext based on the entity i used. However, after upgrading to 0.9.3.0, I have errors with "Found more than one concrete type for given DbContext Type".

    So, yes please let me know if there is a way that i can avoid creating custom repository for each module i have.

  • User Avatar
    0
    hikalkan created
    Support Team

    I suppose this will solve your problem: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1119">https://github.com/aspnetboilerplate/as ... ssues/1119</a>

  • User Avatar
    0
    mengvisal created
    Support Team

    How do i get this update since I only use the library from Nuget-Packages?

  • User Avatar
    0
    hikalkan created
    Support Team

    It will be released in this weekend (probably today).

  • User Avatar
    0
    mengvisal created
    Support Team

    I am not so sure how to use this attribute correctly: DefaultDbContextAttribute. Do I need to apply them to all bounded contexts i have or something else?

  • User Avatar
    0
    hikalkan created
    Support Team

    No, just apply it to the one (non-abstract) dbcontext. Continue this discussion here: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1097">https://github.com/aspnetboilerplate/as ... ssues/1097</a>