2

I am carrying out a project in C# and at the moment I am making the methods to be consumed via API Rest. I want to make an HttpGet that receives a List ids as a parameter.

I want to be able to use the Entity Framework!!

I know that in my Controller the method has this structure

[HttpGet]
public async Task<IActionResult> SearchListIds(IList<long> ids)
        {
            return Response(_mapper.Map<IList<MyViewModel>>(_repository.GetListIds));
        }

My question is how can I do the method in my Repository, I don't know how I can implement the method to make this query in the database, with several ids, I know that in sql it is this way select * from MyTable where id in (1,2,4,5)

For now my repository looks like this:

public ICollection<MyModel> GetListIds(IList<long> ids)
        {

// Incomplete example, because I don't know how I can make this return for the database search, I know that in the end I need to add the .ToList ()

            return Db.MyModel.AsNoTracking()
        }

Can anybody help me? If there's anything wrong with my code, you can tell me too, please.

user7845
  • 43
  • 5

0 Answers0