Domanda

Ho scritto un piccolo query e in LINQPad il suo lavoro bene, ma (vedi sotto) Tariffe non viene restituito come IQueryable, qualcuno sa come risolvere questo problema?

In sostanza vedi tariffe = 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
   }
}

Ho provato questo, ma la sua valida perché GVT non è una tabella o qualcosa del genere?

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

Naturalmente GVT contiene solo i valori che voglio perché ha join interno ...

ho potuto fare solo tirare direttamente dai miei MyTariffs (che funziona restituisce IQueryable), ma poi ho troppo informazioni come la sua non prendendo in considerazione il unisco che ho fatto 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
   select new
   { 
     Deposit = gvt.CurrentDeposit
   }
}
È stato utile?

Soluzione

Selezionare i dati in una sottoquery - sei sicuro che Id == 3 e Id == v.IdTariff? Se questo è davvero il caso, allora si potrebbe aggiungere una clausola in cui la query esterna per selezionare solo quando v v.IdTariff == 3. Sto assumendo, però, che tutti si desidera.

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

esempio raggruppato (non compilato / non testato), in risposta ai vostri commenti.

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
        };
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top