Entity Framework has some async methods. You should use ToListAsync() but your method has to return the complete object. When you receive the object returned by the method, then you can use the Select method to get what you want.
public async Task<IEnumerable<Intermediary>> GetTest(string company)
{
var db = new SibaCiidDbContext();
var results = (from o in db.Intermediary where o.CompanyCode == company select o);
return await results.ToListAsync();
}
So after this you can use it like this
List<Intermediary> objectList = await object.GetTest(nameCompany);
var anotherList = objectList.Select(o => new {
CODE = o.CompanyCode,
NAME = o.FullName
});
if you want to return just these properties, then you might create an object with these properties. For example:
public class SomeObject
{
public string CODE { get; set; }
public string Name { get; set; }
}
public async Task<IEnumerable<SomeObject>> GetTest(string company)
{
var db = new SibaCiidDbContext();
var results = (from o in db.Intermediary where o.CompanyCode == company select new SomeObject{CODE = o.CompanyCode, NAME = o.FullName });
return await results.ToListAsync();
}
0
solved Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable