I have this class that is linked to a View in the SQL Server:
[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; }
}
but when I try to make a list of it like this:
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());
}
nothing happens. Could it be because of the relationships?
Note: All classes are linked to views and work fine with the others except my Client class.
Try passing a string to Include(). Ex:
var clients = db.Clients.Include("Branch").Include("City");