使用延迟加载,包含在包含和访问LastOrDefault记录的属性

时间:2015-05-04 15:43:39

标签: c# asp.net-mvc entity-framework view include

视图

<img src="@product.ImageSet.Images.LastOrDefault().ImageUrl" />   not working
<p>@product.ImageSet.Images.count</p>    is working

控制器

using (var balikciContext = new BalikciContext())
        {
            var model = new ProductViewModel
            {
                Products = balikciContext.Products.Include("ImageSet").Include("ImageSet.Images").ToList(),
                Categories = balikciContext.Categories.Where(c => c.ModuleId == 3).ToList()
            };
            return View(model);
        }

我有经典错误消息&#34;对象引用没有设置为对象的实例&#34;

问题是什么

0 个答案:

没有答案