1

我有这个类链接到 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; }
}

但是当我尝试像这样列出它时:

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类之外的其他类一起正常工作。

4

1 回答 1

0

尝试将字符串传递给 Include()。前任:

var clients = db.Clients.Include("Branch").Include("City");

于 2012-11-02T20:20:49.390 回答