知道 Inbox.Id
要查询出关联的 Attach  List集合该怎么写?List<MailAttach> mailAttachs = db.Inbox.Where(a => a.Id == inboxId).Select(a => a.Mail.MailAttach).ToList(); 这样投影也不行啊?
Attach.where(s=>s.MailAttach.Mail.Inbox.ID == ID)这样写也不行,
Attach.where(s=>s.MailAttach.  到这一步后,后边的东西就出不来了

解决方案 »

  1.   

    var mail = db.Mail.Include("MailAttach").Where(a => aInbox.Id == inboxId )
                 .Select(a=>a.MailAttach).ToList();
      

  2.   


    能把Include("MailAttach.Attach")也包括进来吗?
    如下:
    var mail = db.Mail.Include("MailAttach.Attach").Where(a => aInbox.Id == inboxId )
                 .Select(a=>a.MailAttach).ToList();
      

  3.   


    不行,在Where(a => a.Inbox 后边的 id 就弹不出来了异常:
    错误 4 无法将 lambda 表达式 转换为类型“string”,因为它不是委托类型 F:\win2008iis\BYVOD\Models\MailBll.cs 164 68 BYVOD
    错误 3 委托“System.Func<WebVOD.Models.Mail,int,bool>”未采用 1 个参数 F:\win2008iis\BYVOD\Models\MailBll.cs 164 68 BYVOD
    错误 5 “System.Data.Objects.DataClasses.EntityCollection<WebVOD.Models.Inbox>”不包含“Id”的定义,并且找不到可接受类型为“System.Data.Objects.DataClasses.EntityCollection<WebVOD.Models.Inbox>”的第一个参数的扩展方法“Id”(是否缺少 using 指令或程序集引用?) F:\win2008iis\BYVOD\Models\MailBll.cs 164 81 BYVOD
      

  4.   

    我先这样写试试 var mail = db.Mail.Include("MailAttach").Where(a => a.Inbox.SingleOrDefault().Id == inboxId).Select(a => a.MailAttach).ToList();
      

  5.   

    var q =
        from c in db.Customers
        join o in db.Orders on c.CustomerID
        equals o.CustomerID into orders
        select new
        {
            c.ContactName,
            OrderCount = orders.Count()
        };