Guzzyman
Guzzyman

Reputation: 561

How do I get the Id of a user given the email address in ASP.NET MVC Entity Framework

I have user information in my database. I wish to get the ID of a user given the email address. To get this in sql you would write the following query code:

SELECT Id FROM TableName WHERE email_address = "[email protected]";

How do I write this using ASP.NET MVC Entity-Framework?

Upvotes: 1

Views: 2425

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239380

Well, it depends entirely on your public API, which we have no visibility into. Generally speaking, it would look something like:

var userId = db.Users
    .Where(m => m.email_address == "[email protected]")
    .Select(m => m.Id)
    .SingleOrDefault();

I suggest you take some time with the tutorials at https://www.asp.net/mvc/overview/models-data, to get your bearings.

Upvotes: 1

Related Questions