2

在我的项目中,我有服务。因此,在服务中,我想加入表格并希望选择多个表格数据。

所以我写了这个绳子。

var query1 = from opv in _opvRepository.Table
                         join o in _orderRepository.Table on opv.OrderId equals o.Id
                         join g in _graduandRepository.Table on opv.graduand_id equals g.graduand_id
                         join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
                         join p in _productRepository.Table on pv.ProductId equals p.Id
                         where (opv.ceremony_id == ceremony_id) &&
                         (!o.Deleted) && (opv.IsHireItem == true)  &&
                         (!p.Deleted) &&
                         (!pv.Deleted) && (opv.ceremony_id == ceremony_id)
                         select opv,g;

但是有错误,我不能选择opv and g.如果我写 select opv;它是可以的。但我想选择两个表。我该怎么做??

4

1 回答 1

1

尝试使用匿名类型,即

query1 = from opv in _opvRepository.Table
                         join o in _orderRepository.Table on opv.OrderId equals o.Id
                         join g in _graduandRepository.Table on opv.graduand_id equals g.graduand_id
                         join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
                         join p in _productRepository.Table on pv.ProductId equals p.Id
                         where (opv.ceremony_id == ceremony_id) &&
                         (!o.Deleted) && (opv.IsHireItem == true)  &&
                         (!p.Deleted) &&
                         (!pv.Deleted) && (opv.ceremony_id == ceremony_id)
                         select new { table1Val = opv,
                                      table2Val = g 
                                     };
于 2012-11-07T09:51:29.273 回答