[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How would i write the the following query in entity to count the number of rows in  a table?

Posted on 2015-01-14
4
Medium Priority
?
126 Views
Last Modified: 2015-01-14
SELECT        COUNT(*) AS CNT
FROM            web_board
WHERE class_number = 45

MY entity code:
NLAMEMEntities2 oe = new NLAMEMEntities2();

var cnt = oe.web_board.Where(x =>) x.class_number == "45").Count();

label1.text = cnt.ToString();

Open in new window

0
Comment
Question by:bmanmike39
  • 3
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 40550624
Except for the extraneous paren and double quotes, does what you have not work?

Corrected
var cnt = oe.web_board.Where(x => x.class_number == 45).Count();

Open in new window

0
 

Author Comment

by:bmanmike39
ID: 40550667
No, I get an error  the class_number is type string.  some of the numbers have letter with them.  

The error says i can't use == operator with in and string
0
 

Author Comment

by:bmanmike39
ID: 40550678
Got it.  Thanks for the help!  I fat fingers some things.  The following worked.

var cnt = oe.web_board.Where(x => x.class_number == "45").Count();

Open in new window

0
 

Author Closing Comment

by:bmanmike39
ID: 40550688
Thanks again!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question