【发布时间】:2015-01-26 03:51:59
【问题描述】:
使用以下两个链接,我已经使用 Repo、工作单元、EF、DI 实现了我的项目。
- http://www.codeproject.com/Articles/814768/CRUD-Operations-Using-the-Generic-Repository-Patte
- http://www.codeproject.com/Articles/838097/CRUD-Operations-Using-the-Generic-Repository-Pat
但过了一段时间,由于遗留数据库,我不得不为两个数据库扩展我的项目。 但到目前为止,我无法扩展我的项目以便可以使用两个数据库。 任何人都可以根据提到的链接向我提供有关使用多个数据库的任何解决方案吗?
提前谢谢你。
更新
核心
**Financial Database**
public class Vou : Entity
{
public Nullable<long> Num { get; set; }
public string Subj { get; set; }
}
**Trading Database**
public class Goods : Entity
{
public long Code { get; set; }
public string Title { get; set; }
}
数据
public interface IDbContext
{
IDbSet<TEntity> Set<TEntity>() where TEntity : Entity;
int SaveChanges();
}
public class IocDbContext : DbContext, IDbContext
{
public IocDbContext()
: base("name=FinancialEntities")
{
}
public new IDbSet<TEntity> Set<TEntity>() where TEntity : Entity
{
return base.Set<TEntity>();
}
}
public interface IRepository< TEntity>
{
TEntity Get(int id);
}
public class Repository<T> : IRepository<T> where T : Entity
{
protected readonly DbContext context;
private IDbSet<T> _entities;
public Repository(IocDbContext context)
{
this.context = context;
}
public void Save()
{
this.context.SaveChanges();
}
}
【问题讨论】:
标签: entity-framework asp.net-mvc-4 dependency-injection repository-pattern structuremap