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

Dotnet Discussion :

linq et colonne de tri parametrable


Sujet :

Dotnet

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    205
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 205
    Points : 206
    Points
    206
    Par défaut linq et colonne de tri parametrable
    Bonjour,

    Je souhaiterai créer une méthode qui exécuterai une requête linq en recevant en paramètre la colonne sur laquelle faire un orderby:

    • Quel serait la signature de la méthode?
    • Quel allure aurait la requête?


    Voici une requête imaginaire pour avoir un exemple de base (paramColum est la colonne en question):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    From u in Datacontext.User
    Select u
    ORDER BY Datacontext.User.paramColum

  2. #2
    Membre averti
    Avatar de SoBaKa
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2006
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juillet 2006
    Messages : 242
    Points : 349
    Points
    349
    Par défaut
    Dynamic Linq ?

    Ca devrait répondre à toutes tes questions
    ****** Analyse/Développeur .Net

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    205
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 205
    Points : 206
    Points
    206
    Par défaut
    Parfait, merci beaucoup

  4. #4
    Membre actif
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    205
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 205
    Points : 206
    Points
    206
    Par défaut
    En fait ca ne semble pas fonctionner (je suis en linq to entities):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Dim profilesQueryTest As IQueryable(Of PROFILE) = Nothing
    
            profilesQueryTest = From p In windocContext.PROFILE _
                                Select p
    
            profilesQueryTest.OrderBy("RES_ID desc, GED_ID")
            Dim test As String = CType(profilesQueryTest, System.Data.Objects.ObjectQuery).ToTraceString()
    resultat:

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    SELECT 
    1 AS [C1], 
    [Extent1].[RES_ID] AS [RES_ID], 
    [Extent1].[GED_ID] AS [GED_ID], 
    [Extent1].[BASE_GED] AS [BASE_GED], 
    [Extent1].[TITLE] AS [TITLE], 
    [Extent1].[AUTHOR_FULL_NAME] AS [AUTHOR_FULL_NAME], 
    [Extent1].[CREATION_DATE] AS [CREATION_DATE], 
    [Extent1].[TYPIST_FULL_NAME] AS [TYPIST_FULL_NAME], 
    [Extent1].[NATURE_ID] AS [NATURE_ID], 
    [Extent1].[NATURE_DESC] AS [NATURE_DESC], 
    [Extent1].[CONSERVATION] AS [CONSERVATION], 
    [Extent1].[FORMAT] AS [FORMAT], 
    [Extent1].[IMPUTATION] AS [IMPUTATION], 
    [Extent1].[DELIVERY_DATE] AS [DELIVERY_DATE], 
    [Extent1].[F_NUM] AS [F_NUM], 
    [Extent1].[NB_PAGES] AS [NB_PAGES], 
    [Extent1].[SUPPORT_SUP] AS [SUPPORT_SUP], 
    [Extent1].[NB_SUPPORT] AS [NB_SUPPORT], 
    [Extent1].[COMMENTS] AS [COMMENTS], 
    [Extent1].[A_IMPUTATION] AS [A_IMPUTATION], 
    [Extent1].[RECEPTION_DOC] AS [RECEPTION_DOC], 
    [Extent1].[STOCKAGE] AS [STOCKAGE], 
    [Extent1].[MCDI] AS [MCDI], 
    [Extent1].[DS_DESTRUCTION] AS [DS_DESTRUCTION], 
    [Extent1].[STATUS] AS [STATUS], 
    [Extent1].[DS_FI] AS [DS_FI], 
    [Extent1].[DS_WINDOC] AS [DS_WINDOC], 
    [Extent1].[DS_NUMERISATION] AS [DS_NUMERISATION], 
    [Extent1].[DS_GED] AS [DS_GED], 
    [Extent1].[DS_MCDI] AS [DS_MCDI], 
    [Extent1].[DS_SAS] AS [DS_SAS], 
    [Extent1].[DS_STOCKAGE] AS [DS_STOCKAGE], 
    [Extent1].[F_NUM_TIME] AS [F_NUM_TIME], 
    [Extent1].[Z_PAGE_COUNT] AS [Z_PAGE_COUNT], 
    [Extent1].[Z_SCAN_USER] AS [Z_SCAN_USER], 
    [Extent1].[Z_SCAN_WKSTATION] AS [Z_SCAN_WKSTATION], 
    [Extent1].[Z_SCAN_DATE] AS [Z_SCAN_DATE], 
    [Extent1].[Z_IS_PAPER] AS [Z_IS_PAPER], 
    [Extent1].[Z_SCAN_LOCATION] AS [Z_SCAN_LOCATION], 
    [Extent1].[Z_SCAN_BATCH] AS [Z_SCAN_BATCH], 
    [Extent1].[Z_BURN_BATCH] AS [Z_BURN_BATCH], 
    [Extent1].[Z_FINGERPRINT] AS [Z_FINGERPRINT], 
    [Extent1].[Z_FILE_NAME] AS [Z_FILE_NAME], 
    [Extent1].[Z_FILE_SIZE] AS [Z_FILE_SIZE], 
    [Extent1].[ARBOX_ID] AS [ARBOX_ID], 
    [Extent1].[AUTHOR_ID] AS [AUTHOR_ID], 
    [Extent1].[CORRESPONDANT_ID] AS [CORRESPONDANT_ID], 
    [Extent1].[DEMANDEUR] AS [DEMANDEUR], 
    [Extent1].[TYPIST_ID] AS [TYPIST_ID], 
    [Extent1].[T_PROCESSUS] AS [T_PROCESSUS]
    FROM [dbo].[PROFILE] AS [Extent1]
    Pas de asc ni de desc en vue

    Pourtant, je fais comme la doc:

    The OrderBy method permits a sequence of orderings to be specified, separated by commas. Each ordering may optionally be followed by asc or ascending to indicate ascending order, or desc or descending to indicate descending order. The default order is ascending. The example

    products.OrderBy("Category.CategoryName, UnitPrice descending")

    orders a sequence of products by ascending category name and, within each category, descending unit price.
    Une idée?

  5. #5
    Membre averti
    Avatar de SoBaKa
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2006
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juillet 2006
    Messages : 242
    Points : 349
    Points
    349
    Par défaut
    d'après ce que tu dis, tu ne fais pas vraiment comme dans la doc :

    products.OrderBy("Category.CategoryName, UnitPrice descending")
    ****** Analyse/Développeur .Net

  6. #6
    Membre actif
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    205
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 205
    Points : 206
    Points
    206
    Par défaut
    ca prend au choix desc ou descending + teste avec les 2 sans resultat

Discussions similaires

  1. Réponses: 6
    Dernier message: 21/01/2013, 08h30
  2. [XL-2007] Comparaison de colonnes et tri sélectif
    Par guyCnet dans le forum Excel
    Réponses: 1
    Dernier message: 16/08/2010, 20h15
  3. [XL-2003] calcul d'une colonne après tri
    Par spico45 dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 06/02/2010, 17h54
  4. afficher les colonnes de tri autrement qu'en mode détail
    Par stars987 dans le forum Windows 7
    Réponses: 1
    Dernier message: 28/10/2009, 00h21
  5. [MFC] CListCtrl: colonnes fixes + tri des items
    Par bigboomshakala dans le forum MFC
    Réponses: 5
    Dernier message: 10/05/2004, 22h54

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