我有这个类链接到SQL Server中的View:
[Table("V_Clients")]
public class Client
{
[Key]
public int ClientId { get; set; }
public short BranchId { get; set; }
public string CorporateName { get; set; }
public string TIN { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Id { get; set; }//NroCi
public short CityId { get; set; }
public short ZoneId { get; set; }
public short SubZoneId { get; set; }
public short VendorId { get; set; }
public short PriceListId { get; set; }
public short CollectorId { get; set; }
[ForeignKey("BranchId")]
public virtual Branch Branch { get; set; }
[ForeignKey("CityId")]
public virtual City City { get; set; }
[ForeignKey("ZoneId")]
public virtual Zone Zone { get; set; }
[ForeignKey("SubZoneId")]
public virtual SubZone SubZone { get; set; }
[ForeignKey("VendorId")]
public virtual Vendor Vendor { get; set; }
[ForeignKey("PriceListId")]
public virtual PriceList PriceLists {get;set;}
[ForeignKey("CollectorId")]
public virtual Collector Collector { get; set; }
}
但是当我尝试像这样列出它时:
public ActionResult Index()
{
var clients = db.Clients.Include(c => c.Branch).Include(c => c.City).Include(c => c.Zone).Include(c => c.SubZone).Include(c => c.Vendor).Include(c => c.PriceLists).Include(c => c.Collector);
return View(clients.ToList());
}
没有任何反应。可能是因为关系?
注意:所有类都链接到视图,并且与Client
类之外的其他类一起正常工作。
答案 0 :(得分:0)
尝试将字符串传递给Include()。例如:
var clients = db.Clients.Include("Branch").Include("City");