LINQ syntax
-
Hi, For some reason no matter what I try, this syntax is erroring out.
var dispQuestions = (from m in demographicList.Where(o => o.customertype=="Patient")).ToList();
It complains having a select or group by. I tried this as well, and it still errors.
var dispQuestions = (from m in demographicList.Where(o => o.customertype=="Patient")).Select().ToList();
any thoughts?
-
Hi, For some reason no matter what I try, this syntax is erroring out.
var dispQuestions = (from m in demographicList.Where(o => o.customertype=="Patient")).ToList();
It complains having a select or group by. I tried this as well, and it still errors.
var dispQuestions = (from m in demographicList.Where(o => o.customertype=="Patient")).Select().ToList();
any thoughts?
vkEmerson wrote:
I tried this as well, and it still errors.
What's that? always include those details in your questions. Besides you have posted your question in wrong forum. Try LINQ forum[^]. Now don't repost this question there, leave it now. Hereafter choose right forum.
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
-
vkEmerson wrote:
I tried this as well, and it still errors.
What's that? always include those details in your questions. Besides you have posted your question in wrong forum. Try LINQ forum[^]. Now don't repost this question there, leave it now. Hereafter choose right forum.
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
I could not find the LINQ forum, under the discussion. I will book mark the linq forum for future. if I try to get
dispQuestions.Count
, there is an error message,
Error 5 Operator '>' cannot be applied to operands of type 'method group' and 'int'
Syntax wise, am I missing the format? I am used to ADO.Net, and new to Linq. Trying to figure the various way to write it. Thanks.
-
Hi, For some reason no matter what I try, this syntax is erroring out.
var dispQuestions = (from m in demographicList.Where(o => o.customertype=="Patient")).ToList();
It complains having a select or group by. I tried this as well, and it still errors.
var dispQuestions = (from m in demographicList.Where(o => o.customertype=="Patient")).Select().ToList();
any thoughts?
The problem here is that you're mixing up the query syntax and the method syntax[^]. When the compiler is complaining that you're missing a
select
, it means that a query-syntax query must end with aselect
statement, but you've tried to fix it by adding a call to theSelect
method. Your query could be written in one of two ways:// Query syntax:
var dispQuestions = (from m in demographicList where m.customertype == "Patient" select m).ToList();// Method syntax:
var dispQuestions = demographicList.Where(o => o.customertype == "Patient").ToList();I tend to prefer the second option, but it's a purely aesthetic choice.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I could not find the LINQ forum, under the discussion. I will book mark the linq forum for future. if I try to get
dispQuestions.Count
, there is an error message,
Error 5 Operator '>' cannot be applied to operands of type 'method group' and 'int'
Syntax wise, am I missing the format? I am used to ADO.Net, and new to Linq. Trying to figure the various way to write it. Thanks.
Try dispQuestions.Count**()** instead.