开发者

LINQ; forcing a new {} to return Iqueryable?

I written a small query and in Linqpad its working well but (see below) Tariffs is not returned as Iqueryable, does anyone know how to fix this ?

Basically see Tariffs = new ....,

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
   }
}

I did try this but its invalid because gvt isn't a table or something?

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
   }
}

Of course gvt contains just the values i want because it has the inner join...

I could do just pull directly from my MyTariffs (which works it returns Iqueryable) but then i have too much info as its not taking into consideration the join which i did in 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
   sele开发者_C百科ct new
   { 
     Deposit = gvt.CurrentDeposit
   }
}


Select the data in a subquery -- are you sure that Id == 3 and Id == v.IdTariff? If that's really the case, then you could add a where clause to the outer query to select only v when v.IdTariff == 3. I'm assuming, though, that you want them all.

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

Grouped example (uncompiled/untested), in response to your comments.

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
        };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜