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
119 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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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