其他分享
首页 > 其他分享> > Abp用多个DbContext

Abp用多个DbContext

作者:互联网

 

using Abp.Domain.Entities;
using Abp.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace report.EntityFramework.Repositories.Second
{
    public interface IRepositorySecond<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey> where TEntity : class ,IEntity<TPrimaryKey>
    {
    }
}

 

using Abp.Domain.Entities;
using Abp.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace report.EntityFramework.Repositories.Second.impl
{
   public class RepositorySecond<TEntity, TPrimaryKey> : reportSecondRepositoryBase<TEntity, TPrimaryKey>, IRepositorySecond<TEntity, TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
    {
        public RepositorySecond(IDbContextProvider<reportSecondDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }
    }
}

 

 

using Abp.Domain.Entities;
using Abp.EntityFramework;
using Abp.EntityFramework.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace report.EntityFramework.Repositories
{
    public abstract class reportSecondRepositoryBase<TEntity, TPrimaryKey> : EfRepositoryBase<reportSecondDbContext, TEntity, TPrimaryKey>
        where TEntity : class, IEntity<TPrimaryKey>
    {
        protected reportSecondRepositoryBase(IDbContextProvider<reportSecondDbContext> dbContextProvider)
            : base(dbContextProvider)
        {

        }

        //add common methods for all repositories
    }
    public abstract class reportSecondRepositoryBase<TEntity> : reportSecondRepositoryBase<TEntity, int>
    where TEntity : class, IEntity<int>
    {
        protected reportSecondRepositoryBase(IDbContextProvider<reportSecondDbContext> dbContextProvider)
            : base(dbContextProvider)
        {

        }

        //do not add any method here, add to the class above (since this inherits it)
    }
}

 

using System.Data.Entity;
using System.Reflection;
using Abp.Dependency;
using Abp.Modules;
using Abp.Zero.EntityFramework;
using report.EntityFramework;
using report.EntityFramework.Repositories.Second;
using report.EntityFramework.Repositories.Second.impl;

namespace report
{
    [DependsOn(typeof(AbpZeroEntityFrameworkModule), typeof(reportCoreModule))]
    public class reportDataModule : AbpModule
    {
        public override void PreInitialize()
        {
            Database.SetInitializer(new CreateDatabaseIfNotExists<reportDbContext>());

            Configuration.DefaultNameOrConnectionString = "Default";
        }

        public override void Initialize()
        {
            //IocManager.Register(typeof(RepositorySecond<,>), DependencyLifeStyle.Singleton);
            IocManager.Register(typeof(IRepositorySecond<,>),typeof(RepositorySecond <,>));
          
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}

 

标签:EntityFramework,多个,System,DbContext,public,Abp,using,class
来源: https://www.cnblogs.com/wangyinlon/p/15122279.html