I'm trying to make a general "GET" in MONGODB. But it does not convert error:

Cannot implicty convert type

enter image description here

My Service

namespace AdmissionAnonymousForm.Infrascructure.Services
{
    public class BankService: IBankService
    {
    private readonly IMongoCollection<Bank> _bank;

    public BankService(IConfiguration config)
    {
        var client = new MongoClient(config.GetConnectionString("AdmissionAnonymous"));
        var database = client.GetDatabase("AdmissionAnonymous");
        _bank = database.GetCollection<Bank>("Bank");
    }

    public  Task<Bank> Get()
    {
        return   _bank.Find(bank => true).ToListAsync();
    }
  }
}

My Model

namespace AdmissionAnonymousForm.Infrascructure.Services.Core
{
    public interface IBankService
    {
        Task<Bank> Get();
        Task<Bank> Get(Guid id);
        Task<Bank> Post(Bank bank);
        void Update(Guid id, Bank addressIn);
        void Delete(Guid id);
    }
}

2 Answers

5
Aarif On Best Solutions

the return type of Get method should be Task<List<Bank>>

public  Task<List<Bank>> Get()
{
    return _bank.Find(bank => true).ToListAsync();
}
1
Marc Ramiro Alpuente On

You are returning a list and is expecting a single object of Bank