optimization - linq query crossjoin groupby optimize -


i have following database-model: http://i.stack.imgur.com/grtmd.png many many relations kunde_geraet/kunde_anwendung in explicit mapping-table additional information.

i want optimize following linq-query:

var qkga = (from es in db.eintrag_systeme.where(es => es.eintrag_id == id)                    kg in db.kunde_geraet.where(kg => es.geraet_id == kg.geraet_id)                    select new { kunde = kg.kunde, geraet = es.geraet, anwendung = es.anwendung })                      .union(                   es in db.eintrag_systeme.where(es => es.eintrag_id == id)                   ka in db.kunde_anwendung.where(ka => es.anwendung_id == ka.anwendung_id)                   select new { kunde = ka.kunde, geraet = es.geraet, anwendung = es.anwendung })                   .groupby(kga => kga.kunde, kga => new {geraet = kga.geraet, anwendung = kga.anwendung}); 

it better, when result ienumerable(kunde, ienumerable(geraet), ienumerable(anwendung)) without null-values union.

i try sql command

select count(es.geraet_id), null anwendung_id eintrag_systeme es cross join kunde_geraet es.geraet_id = kunde_geraet.geraet_id , es.eintrag_id = @id union select null geraet_id, count(es.anwendung_id) eintrag_systeme es cross join kunde_anwendung es.anwendung_id = kunde_anwendung.anwendung_id , es.eintrag_id = @id group kunde_id 

but don´t count() of anwendungen(apps)/geraete(devices) lists grouped key kunde(client)

don't use join navigation properties:

from k in context.kunden select new {     kunde = k,     geraete = k.kunde_geraete.select(kg => kg.geraet),     anwendungen = k.kunde_anwendungen.select(ka => ka.anwendung) } 

now have basis counts, etc.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -