TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jacques Sandler
NA
5
3.2k
C# Linq Select Many
Jan 3 2012 9:02 AM
Hi All,
I am matching Cases to Controls, basically records in the Case list, need to have the number of matches that is specified in the string 'm_ctrlno'.
So far i have two lists, the where clause is correct, however i'm unsure how to use SelectMany to get the 3 Controls that match 1 Case. I decided to use the .Take() function however it doesn't seem to be working. I'm not getting the same case with 3 different controls when i cycle on the var query.
Any ideas?
Many thanks
J.
Here is the code:
List<CaseSelection> CurrentCaseList = new List<CaseSelection>();
foreach (CaseSelection CurrentCase in m_casesarraylist)
CurrentCaseList.Add(CurrentCase);
List<ControlSelection> CurrentControlList = new List<ControlSelection>();
foreach (ControlSelection CurrentControlRec in ControlList)
CurrentControlList.Add(CurrentControlRec);
var query = CurrentCaseList.SelectMany(
c => CurrentControlList.Where(o => o.pracid == c.pracid && o.sex == c.sex &&
CaseSelectionList.AgeIsInRange(c.yob, o.yob, m_years)),
(c, o) =>
new { o, c }).Take(m_ctrlno);
Reply
Answers (
3
)
The problem with sqlmetal command
Returning Complete Sequence