IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

LINQ / Optimisation


Sujet :

C#

  1. #1
    Membre actif
    Homme Profil pro
    Architecte technique
    Inscrit en
    Février 2004
    Messages
    477
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 477
    Points : 223
    Points
    223
    Par défaut LINQ / Optimisation
    Bonjour à tous,

    Est ce que vous voyez un moyen de faire ces 2 requêtes LINQ en 1X ?
    La 1ère requête me remonte les points manquants, la 2ème me remonte les points avec une puissance différente.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
     
    List<GTMPoint> newListPoint = (from gtmPtInList in listPointWithout25H
                                                   join gtmPtInDb in listPointDbWithout25H on gtmPtInList.IIdTypePoint equals gtmPtInDb.IIdTypePoint into sameTypePt
                                                   join gtmPtInDb in listPointDbWithout25H on gtmPtInList.LIdCounter equals gtmPtInDb.LIdCounter into sameCptId
                                                   join gtmPtInDb in listPointDbWithout25H on gtmPtInList.DtPoint equals gtmPtInDb.DtPoint into sameDatePoint
                                                   from t in sameDatePoint.DefaultIfEmpty()
                                                   where t == null
                                                   select new GTMPoint(
                                                       gtmPtInList.LIdCounter,
                                                       (GTMEnum.GTMTypePt)gtmPtInList.IIdTypePoint,
                                                       1,
                                                       gtmPtInList.DPuissance,
                                                       gtmPtInList.DtPoint,
                                                       gtmPtInList.DtVersion,
                                                       gtmPtInList.CValidation,
                                                       gtmPtInList.GtmGranularite
                                                   )).ToList();
     
     
    List<GTMPoint> updatedListPoint = (from gtmPtInList in listPointWithout25H
                                                       join gtmPtInDb in listPointDbWithout25H on gtmPtInList.IIdTypePoint equals gtmPtInDb.IIdTypePoint into sameTypePt
                                                       join gtmPtInDb in listPointDbWithout25H on gtmPtInList.LIdCounter equals gtmPtInDb.LIdCounter into sameCptId
                                                       join gtmPtInDb in listPointDbWithout25H on gtmPtInList.DtPoint equals gtmPtInDb.DtPoint into sameDatePoint
                                                       from t in sameDatePoint.DefaultIfEmpty()
                                                       where t != null && (float)gtmPtInList.DPuissance != (float)t.DPuissance
                                                       select new GTMPoint(
                                                           t.LIdCounter,
                                                           (GTMEnum.GTMTypePt)t.IIdTypePoint,
                                                           t.IVersion + 1,
                                                           gtmPtInList.DPuissance,
                                                           gtmPtInList.DtPoint,
                                                           gtmPtInList.DtVersion,
                                                           gtmPtInList.CValidation,
                                                           gtmPtInList.GtmGranularite
                                                       )).ToList();

  2. #2
    Expert confirmé

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 065
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 065
    Points : 4 229
    Points
    4 229
    Par défaut
    Pourquoi ne pas faire un union entre les 2 ?
    Sinon je pense tu peux peut être faire 2 jointure distincte sur la même table

  3. #3
    Membre actif
    Homme Profil pro
    Architecte technique
    Inscrit en
    Février 2004
    Messages
    477
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 477
    Points : 223
    Points
    223
    Par défaut
    La solution était dans la question, avec une bonne vieille ternaire ça fonctionne, je partage:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
       newListPoint.AddRange((from gtmPtInList in listPt
                                           join gtmPtInDb in listPtInDB on gtmPtInList.IIdTypePoint equals gtmPtInDb.IIdTypePoint into sameTypePt
                                           join gtmPtInDb in listPtInDB on gtmPtInList.LIdCounter equals gtmPtInDb.LIdCounter into sameCptId
                                           join gtmPtInDb in listPtInDB on gtmPtInList.DtPoint equals gtmPtInDb.DtPoint into sameDatePoint
                                           from t in sameDatePoint.DefaultIfEmpty()
                                           where (t == null) || (t != null && (float)gtmPtInList.DPuissance != (float)t.DPuissance)
                                           select new GTMPoint(
                                               gtmPtInList.LIdCounter,
                                               (GTMEnum.GTMTypePt)gtmPtInList.IIdTypePoint,
                                               t == null ? 1 : t.IVersion + 1,
                                               gtmPtInList.DPuissance,
                                               gtmPtInList.DtPoint,
                                               gtmPtInList.DtVersion,
                                               gtmPtInList.CValidation,
                                               gtmPtInList.GtmGranularite
                                           )).ToList());

  4. #4
    Expert confirmé

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 065
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 065
    Points : 4 229
    Points
    4 229
    Par défaut
    Attention l'utilisation d'un Or dans ton where peut affecter les performances de ta requête parfois un union peut être plus perf ...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Optimisation (LINQ ?)
    Par dacid dans le forum Général Dotnet
    Réponses: 11
    Dernier message: 22/07/2016, 12h47
  2. Réponses: 2
    Dernier message: 19/11/2015, 16h55
  3. Optimisation requête XML - LinQ
    Par jeyGey dans le forum Linq
    Réponses: 2
    Dernier message: 25/09/2014, 17h57
  4. Optimisation d'utilisation LINQ to XML
    Par Andrian dans le forum C#
    Réponses: 0
    Dernier message: 04/02/2013, 11h28
  5. Linq - question optimisation requête
    Par boby62423 dans le forum Linq
    Réponses: 2
    Dernier message: 07/04/2009, 19h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo