Osvaldo
Osvaldo

Reputation: 23

How to get a list of users on a birthday table in a given month?

I want to get the list of users (UserId) who celebrate their birthday in the months of February and August

I have already tried these:

public ActionResult Test()
{
   var Model = db.Users.Where(u => u.Birthday.Value.Month == 02);


public ActionResult Test()
{
    var Model = db.Users.Where(u => u.Birthday.Value.Month == 02).ToList();

I expected a list of UserId that celebrate birthday in the months of February and August.

Upvotes: 0

Views: 217

Answers (2)

Kim Lage
Kim Lage

Reputation: 117

try this:

var model = db.Users.Where(u => u.Birthday.Value.Month == 02).Select(c=>c.UserId).ToList();

that shoud give you the list with the UsersID ( for february) if you want both months try:

    var model = db.Users.Where(u => u.Birthday.Value.Month == 02 || u.Birthday.Value.Month == 08).Select(c=>c.UserId).ToList();

Upvotes: 1

Sreenivas Gurram
Sreenivas Gurram

Reputation: 126

Try This

var Model = db.Users.Where(u => u.Birthday.Month == 02 || u.Birthday.Month == 08).ToList();

Upvotes: 1

Related Questions