0

我写了一个小查询,在 Linqpad 中运行良好,但是(见下文)关税不作为 Iqueryable 返回,有谁知道如何解决这个问题?

基本上看关税=新......,

from v in House
join gvt in
    (from t in MyTariffs where t.Id == 3 select t)
on v.IdTariff equals gvt.Id
select new
{
   Id = v.Id,
   Tariffs = new
   { 
     Deposit = gvt.CurrentDeposit
   }
}

我确实尝试过,但它无效,因为 gvt 不是表格或其他东西?

from v in House
join gvt in
    (from t in MyTariffs where t.Id == 3 select t)
on v.IdTariff equals gvt.Id
select new
{
   Id = v.Id,
   Tariffs = from x in gvt   // NOTICE i am doing from x in gvt... But it fails..
   select new
   { 
     Deposit = gvt.CurrentDeposit
   }
}

当然 gvt 只包含我想要的值,因为它有内部连接......

我可以直接从我的 MyTariffs 中提取(它可以返回 Iqueryable)但是我有太多信息,因为它没有考虑到我在 gvt 中所做的加入?

from v in House
join gvt in
    (from t in MyTariffs where t.Id == 3 select t)
on v.IdTariff equals gvt.Id
select new
{
   Id = v.Id,
   Tariffs = from x in MyTariffs // THIS has nothing to do with my join
   select new
   { 
     Deposit = gvt.CurrentDeposit
   }
}
4

1 回答 1

2

选择子查询中的数据——您确定 Id == 3Id == v.IdTariff?如果确实如此,那么您可以在外部查询中添加一个 where 子句,以便在 v.IdTariff == 3 时仅选择 v。不过,我假设您想要所有这些。

var q = from v in House
        select new {
            Id = v.Id,
            Tariffs = (from g in MyTariffs
                       where g.Id == v.IdTariff
                       select g.CurrentDeposit)
        };

分组示例(未编译/未经测试),以响应您的评论。

var q = from v in House
        join g in (from t in MyTariffs where t.Id == 3 select t)
        group by v.Id into gvt
        select new {
            Id = gvt.Key,
            Tariffs = gvt.g
        };
于 2009-11-01T12:49:15.667 回答