在显示关系属性时出现问题b / w两个表有一个(公司)到多个(package_master)关系
动作
public ViewResult Index()
{
var companies = db.companies.Include(c => c.aspnet_Users)
.Include(c=>c.package_master);
return View(companies.ToList());
}
的EntitySet
public partial class company
{
public company()
{
this.package_master = new HashSet<package_master>();
}
public int company_id { get; set; }
public string name { get; set; }
public string address { get; set; }
public string phone { get; set; }
public string fax { get; set; }
public Nullable<System.Guid> sen_sup { get; set; }
public virtual aspnet_Users aspnet_Users { get; set; }
public virtual ICollection<package_master> package_master { get; set; }
}
当我键入Model.aspnet_Users.property1
时,一切正常(智能感知)但现在我也想从packege_master(无intellisense)中显示属性(外键表= package_master,其中client_id为外键,公钥表=公司有company_id作为主键)
答案 0 :(得分:2)
package_master
是一个集合。您无法直接访问package_master实体的成员属性,如:Model.package_master.XXX
。您必须迭代集合才能访问实体。