我正在寫一個基於史蒂夫桑德森的臨Asp.Net MVC框架的應用程序,該應用程序使用數據建模,如該書上體育商店應用程序中所述。我的應用程序運行良好,我使用Castle項目作爲IOC,但我有兩個數據庫。第一個存儲多種數據和我的客戶信息。第二個只存儲每個客戶的醫療數據。我需要創建一個類,在客戶表中返回的數據,位於數據庫1和每個客戶的醫療信息存儲在數據庫2.MVC多個數據庫在一個單一的域模型
下面是我的代碼:
我在web.config中的ConnectionStrings:
<add name="CNRConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=CNR;Persist Security Info=True;User ID=sa;[email protected]#@@@!" providerName="System.Data.SqlClient"/>
<add name="CNRpeConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=pe;Persist Security Info=True;User ID=sa;[email protected]#@@@!" providerName="System.Data.SqlClient"/>
我的新類(不僅僅是數據,無表連接如):
namespace DomainModel.Entities
{
public class ImprimePeriodoPaciente
{
public int CodConsulta { get; set; }
public DateTime DataConsulta { get; set; }
public string Evolucao { get; set; }
public int CodProfissional1 { get; set; }
public int CodPaciente1 { get; set; }
public string NomeProfissional { get; set; } //receives data from other db
public string NomePaciente { get; set; } //receives data from other db
public int CodProcedimento { get; set; }
public bool TagConsulta { get; set; }
public int? TagConsulta2 { get; set; }
public DateTime di { get; set; }
public DateTime df { get; set; }
}
}
這是我的混凝土和接口從的DomainModel:
public class SqlConsultasRepository:IConsultasRepository
{
private Table<Consulta> consultasTabela;
private Table<TEvolucao> tEvolucaoTabela;
private Table<Paciente> pacientesTabela;
private Table<Funcionario> funcionariosTabela;
public SqlConsultasRepository(string connectionString)
{
consultasTabela = (new DataContext(connectionString)).GetTable<Consulta>();
tEvolucaoTabela = (new DataContext(connectionString)).GetTable<TEvolucao>();
pacientesTabela = (new DataContext(connectionString)).GetTable<Paciente>();
funcionariosTabela = (new DataContext(connectionString)).GetTable<Funcionario>();
}
public IQueryable<ImprimePeriodoPaciente> Prontuarios {
get
{
return
(
from c in consultasTabela
join p in pacientesTabela on c.CodPaciente1 equals p.CodigoPaciente //my doom
join f in funcionariosTabela on c.CodProfissional1 equals f.CodigoFuncionario //my doom
select new ImprimePeriodoPaciente
{
CodConsulta=c.CodConsulta,
DataConsulta=c.DataConsulta,
Evolucao=c.Evolucao,
NomeProfissional= f.NomeFuncionario, //my doom
NomePaciente=p.NomePaciente, //my doom
CodProfissional1=c.CodProfissional1,
CodPaciente1 = c.CodPaciente1
}
);
}
}
代碼用'my doom'標記以顯示出現問題的位置....我需要創建對其他數據庫的connectionString引用,因爲這些表不在由connectionString變量指定的當前數據庫中。我收到錯誤,說數據不是來自同一個datacontext(或類似的東西)。
那麼,你能幫忙嗎?
我已閱讀Pro Asp.Net MVC 3,並且我建議您避開Sports Store應用程序示例。這是我生命中見過的最瘋狂,病態過度設計和不切實際的代碼。 史蒂夫桑德森寫框架和書籍,但這些不是現實生活中的應用程序,當所有的例子不粘在一起 這不是一個大問題。 –
嗯,我知道他的生活方式看起來很艱難,但我不認爲我沒時間重新生成我的應用程序,因爲我沒有這個時間...... Tnx對於您的建議....下一個應用程序won''t不要這樣。 – Bodyslicer