Linq关系表包括 [英] Linq relational table include

查看:75
本文介绍了Linq关系表包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个关系表;

  1. 类别
  2. 产品
  3. ProductBrand
  4. ProductImage

我需要linq查询包括 3个表,并按ProductBrand from CategoryId分组.

I need linq query included 3 tables group by ProductBrand from CategoryId.

我尝试这个;

var PBrand = from b in db.ProductBrands
                       join p in db.Products on b.BrandId equals p.BrandId
                       join i in db.ProductImages on p.ProductId equals i.ProductId 
                       where b.CategoryId == 5
                       select b;

,但ProductsProductImages为空.如何在Brand表上包含ProductsProductImages表?

but Products and ProductImages are null. How I include Products and ProductImages table on Brand table?

推荐答案

使用

扩展方法Include .

这篇关于Linq关系表包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆