Précédent   Forum des professionnels en informatique > Dotnet > Accès aux données > Linq
Linq Forum d'entraide sur la manipulation de données avec Linq
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/01/2012, 14h38   #1
Membre habitué
 
Inscription : décembre 2007
Messages : 579
Détails du profil
Informations personnelles :
Localisation : France, Seine Maritime (Haute Normandie)

Informations forums :
Inscription : décembre 2007
Messages : 579
Points : 114
Points : 114
Par défaut gestion difficile des relations many-to-many

bonjour,

alors pour faire simple, j'ai une entité personnalisée "EntityTutorial", laquelle est composée des tables tbl_Article et tbl_ArticleTutorial.
La table tbl_Article contient une collection de tbl_skill...

j'ai créé la fonction suivante :
Code :
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
protected static List<Entity_Tutorial> GetPublishedList(string keyword, Guid[] skillIds, DateTime? articleBegin, DateTime? articleEnd, int skip, int take)
        {
            List<Entity_Tutorial> tutorialList = (from tutorial in Access.db.tbl_ArticleTutorial
                                                join article in Access.db.tbl_Article on tutorial.Article_id equals article.Article_id
                                                orderby article.Article_published_at descending
                                                where article.Article_is_published == true
                                                select new Entity_Tutorial() { Article = article, ArticleTutorial = tutorial }).ToList();
 
            if(keyword != string.Empty)
            {
                string[] keywordList = keyword.Split(' ');
                tutorialList = (from tutorial in tutorialList
                                 from search in keywordList
                                 where tutorial.Text.Contains(search) || tutorial.Title.Contains(search)
                                 select tutorial).ToList();
            }
 
            if (skillIds != null)
            {
 
            }
 
            if (articleBegin != null)
            {
                tutorialList = (from tutorial in tutorialList
                                where tutorial.PublishedDate >= articleBegin
                                select tutorial).ToList();
            }
 
            if (articleEnd != null)
            {
                tutorialList = (from tutorial in tutorialList
                                where tutorial.PublishedDate <= articleEnd
                                select tutorial).ToList();
            }
 
            return tutorialList.Skip(skip).Take(take).ToList();
        }
J'ai géré correctement la plupart des points de ma fonction, excepté la recherche avec mon élément Guid[] skillIds.
Mon but : rechercher tous les tutoriaux ayant les Id de skill passés en paramètres.

voici comment communiquer avec la collection :
Code :
1
2
tutorialList = (from tutorial in tutorialList
                                where tutorial.Article.tbl_Skill).ToList();
j'ai commencé à utiliser le Linq il y a peu de temps, je ne suis pas encore très bien familiarisé j'avoue :/
thor76160 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 21h20   #2
Membre Expert
 
Avatar de GuruuMeditation
 
Homme Olivier Matis
Software Architect
Inscription : octobre 2010
Messages : 769
Détails du profil
Informations personnelles :
Nom : Homme Olivier Matis
Âge : 37
Localisation : Belgique

Informations professionnelles :
Activité : Software Architect
Secteur : Conseil

Informations forums :
Inscription : octobre 2010
Messages : 769
Points : 1 589
Points : 1 589
Envoyer un message via MSN à GuruuMeditation
Essaye un truc comme :
Code c# :
1
2
 
var tutoriels = from tutorial in tutorialist where skillIds.contains(tutorial.Article.tbl_skills) select tutorial;
__________________
Microsoft MVP : Visual C#

MCPD - Windows Developer 4
MCPD - Web Developer 4
MCTS - Silverlight 4, Development

“If debugging is the process of removing bugs, then programming must be the process of putting them in.”
(Edsger W. Dijkstra)
GuruuMeditation est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h53.


 
 
 
 
Partenaires

Hébergement Web