实体框架代码第一相关数据未加载

时间:2016-02-21 19:31:21

标签: c# winforms entity-framework datagrid devexpress

我想在产品负载上将产品类别和制造商加载到devexpress数据网格中,但产品的多对一类别未加载

这是对象的代码

      public class Product
{
    public Product() 
    {
        Weight = 0;
        Height = 0;
        Width = 0;
        Length = 0;
      ProductCategory = new Category();
      ProductManufacturer = new Manufacturer();
     ProductPictures = new List<Pictures>();



    }

    [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity), Column(Order = 0)]
    public long Id { get; set; }
[Required]
    public string ProductName { get; set; }

    [DataType(DataType.Currency)]
    public decimal Price { get; set; }
    public long CategoryId { get; set; }
     [ForeignKey("CategoryId")]
    public virtual Category ProductCategory { get;  set; }
     public long ManufacturerId { get; set; }
     [ForeignKey("ManufacturerId")]
    public virtual Manufacturer ProductManufacturer { get;  set; }

    public bool IsFragile { get; set; }

    public decimal Weight { get; set; }


    public decimal Height { get; set; }

    public decimal Width { get; set; }

    public decimal Length { get; set; }



    public virtual ICollection<Pictures> ProductPictures { get; private set; }

    [DataType(DataType.MultilineText)]
    public string ItemDescription { get; set; }
}

加载和绑定源

        dbContext.Product.Include(x => x.ProductManufacturer).Include(x => x.ProductCategory).Load();

        bindingSource1.DataSource = dbContext.Product.Include(x => x.ProductManufacturer).Include(x => x.ProductCategory).ToList();

然而,在表单加载时,产品类别始终为null。在调试时,我意识到它没有运行类别字段的选择查询

0 个答案:

没有答案
相关问题