Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert this to non SQL like LINQ
Message
De
09/10/2014 10:50:37
John Baird
Coatesville, Pennsylvanie, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01609048
Message ID:
01609053
Vues:
58
>Looks promising thanks John.

You realize there's no benefit of one over the other. They all compile to same IL code.... just a matter of preference. and in certain cases with multiple join conditions, it can become a nightmare to use fluent syntax.

example: this is easier to read
  var query = (from c in _dbc.Checklist.Where(w => w.FK_TaxList == taxKey && w.PK_Checklist == clKey)
                                 from cld in _dbc.ChecklistData.Where(w => w.FK_Checklist == c.PK_Checklist)
                                 from tx in _dbc.Taxonomy.Where(w => w.FK_Thing == cld.FK_Thing)
                                 from t in _dbc.Thing.Where(w => w.PK_Thing == tx.FK_Thing)
                                 from g in _dbc.Genus.Where(w => w.PK_Genus == tx.FK_Genus)
                                 from sp in _dbc.Species.Where(w => w.PK_Species == tx.FK_Species)
                                 from sb in _dbc.SubSpecies.Where(sb => sb.PK_SubSpecies == tx.FK_SubSpecies).DefaultIfEmpty()
                                 select new { t.PK_Thing, CommonName = t.Name, Genus = g, Species = sp, SubSpecies = sb }).ToList();
than this and they both do the same thing.
                    var query = (_dbc.Checklist.Where(w => w.FK_TaxList == taxKey && w.PK_Checklist == clKey)
                        .SelectMany(c => _dbc.ChecklistData.Where(w => w.FK_Checklist == c.PK_Checklist),
                            (c, cld) => new {c, cld})
                        .SelectMany(@t1 => _dbc.Taxonomy.Where(w => w.FK_Thing == @t1.cld.FK_Thing),
                            (@t1, tx) => new {@t1, tx})
                        .SelectMany(@t1 => _dbc.Thing.Where(w => w.PK_Thing == @t1.tx.FK_Thing),
                            (@t1, t) => new {@t1, t})
                        .SelectMany(@t1 => _dbc.Genus.Where(w => w.PK_Genus == @t1.@t1.tx.FK_Genus),
                            (@t1, g) => new {@t1, g})
                        .SelectMany(@t1 => _dbc.Species.Where(w => w.PK_Species == @t1.@t1.@t1.tx.FK_Species),
                            (@t1, sp) => new {@t1, sp})
                        .SelectMany(
                            @t1 =>
                                _dbc.SubSpecies.Where(sb => sb.PK_SubSpecies == @t1.@t1.@t1.@t1.tx.FK_SubSpecies)
                                    .DefaultIfEmpty(),
                            (@t1, sb) =>
                                new
                                {
                                    @t1.@t1.@t1.t.PK_Thing,
                                    CommonName = @t1.@t1.@t1.t.Name,
                                    Genus = @t1.@t1.g,
                                    Species = @t1.sp,
                                    SubSpecies = sb
                                })).ToList();
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform