0

how can I get the count of records in the table users in the applicationContextcreatedin the mvc project?

this is what I have tried so far:

var context = new ApplicationDbContext();
var count = context.Users
.Where(o => Convert.ToInt32(o.Id) == 1)
.Count();

if (count < 3)
{

//do whatever

}

it's giving an error at the convert.ToInt32, and if I remove the convert it will give an error cannot implicity convert type 'string' to 'int' (o.Id) == 1)

what is going wrong?

2 Answers 2

1

context.Users.Count() should work. Am I missing something obvious here?

Sign up to request clarification or add additional context in comments.

Comments

1

Can you not just compare it as a string if thats what it is?

var context = new ApplicationDbContext();
var count = context.Users
.Where(o => o.Id == "1")
.Count();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.