我有两个连接字符串都连接到数据库
<connectionStrings>
<add name="EISystemEntities" connectionString="metadata=res://*/Models.EISystemModel.csdl|res://*/Models.EISystemModel.ssdl|res://*/Models.EISystemModel.msl;provider=System.Data.SqlClient;provider connection string="data source=***-DEV-APP01;initial catalog=EISystem;persist security info=True;user id=****;password=*****;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="UserAccountsDBEntities" connectionString="metadata=res://*/Models.DB.UserAccountsModel.csdl|res://*/Models.DB.UserAccountsModel.ssdl|res://*/Models.DB.UserAccountsModel.msl;provider=System.Data.SqlClient;provider connection string="data source=***-DEV-APP01;initial catalog=EISystem;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
我有一个MultipleViewModel设置
namespace EISystem.Models
public class MultipleModelViewModel
{
public company CompanyEntities { get; set; }
public Description Descriptions { get; set; }
public Company_Contact ContactEntities { get; set; }
public ComType TypeEntities { get; set; }
public country CountryEntities { get; set; }
public Year_Established EstablishedEntities { get; set; }
public Employee employeeEntities { get; set; }
public Region RegionEntities { get; set; }
public Region ExportRegionEntities { get; set; }
public Register_Title TitleEntities { get; set; }
public SYSUser UserEntities { get; set; }
}
注意:SYSUser是第二个连接字符串的一部分,即UserAccountsDBEntities
如何在VIEW中访问第二个连接字符串(UserAccountsDBEntities)的字段
比如@Html.DisplayFor(m => m.ContactEntities.ContactID)
“0”当前显示为“
答案 0 :(得分:0)
决定改为创建一个connectionString。和implimant MultipleModelView类
public class MultipleModelViewModel
{
public MultipleModelViewModel()
{
TitleEntities = new Register_Title();
ContactEntities = new Company_Contact();
CompanyEntities = new company();
//Descriptions = new Description();
CountryEntities = new country();
EstablishedEntities = new Year_Established();
UserEntities = new SYSUser();
UserRoleEntities = new SYSUserRole();
UserProfileEntities = new SYSUserProfile();
}
public company CompanyEntities { get; set; }
public Description Descriptions { get; set; }
public Company_Contact ContactEntities { get; set; }
public ComType TypeEntities { get; set; }
public country CountryEntities { get; set; }
public Year_Established EstablishedEntities { get; set; }
public Employee employeeEntities { get; set; }
public Region RegionEntities { get; set; }
public Region ExportRegionEntities { get; set; }
public Register_Title TitleEntities { get; set; }
public SYSUser UserEntities { get; set; }
public SYSUserRole UserRoleEntities { get; set; }
public SYSUserProfile UserProfileEntities { get; set; }
}