Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ASP.NET Core – Get tuple with two values

I just want to get the user’s role and ID from the user table. But I do not know why the following code gives an error!!!

public Tuple<Guid,Guid> GetUserId(string mobile)
{
    return _context.Users.Select(u => new Tuple<Guid,Guid,Boolean>(u.UserId,u.RoleId,u.Mobile == mobile));
}

I searched a lot but did not find an answer?

Error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

error image

>Solution :

Meanwhile, your existing code will return IEnumerable<Tuple<Guid,Guid>> or IQueryable<Tuple<Guid,Guid>>, which un-match with the method return type, Tuple<Guid,Guid>.

Assume that you are trying to filter with mobile.

You need either of these methods:

to return (single) result Tuple<Guid,Guid>.

public Tuple<Guid,Guid> GetUserId(string mobile)
{
    return _context.Users
        .Where(u => u.Mobile == mobile)
        .Select(u => new Tuple<Guid,Guid>(u.UserId,u.RoleId))
        .First();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading