2
Cannot convert type implicitly "System.Collections.Generic.IEnumberable<SS_API.Model.Project>" em "Microsoft.AspNetCore.Mvc.ActionResult<System.Collections.Generic.Inumerable<string>>".
How could I make the class call on controller
correctly?
Interface:
public interface IAcess : IDisposable
{
IEnumerable<Project> GetProjects();
Project GetProject(int id);
void AddProject(Project item);
void DeleteProject(int id);
void UpdateProject(Project item);
void Save();
}
Class:
public class Acess : IAcess
{
private Project project = new Project();
private StreamerContext context;
public Acess(StreamerContext streamer)
{
this.context = streamer;
}
public IEnumerable<Project> GetProjects()
{
return context.Project.ToList();
}
}
Controller:
public ActionResult<IEnumerable<string>> Get()
{
var projects = from project in _acess.GetProjects()
select project;
return projects;
}
I appreciate your help. I was able to solve the problem by leaving the code as follows: public Actionresult<Ienumerable<Project>> Get() { var Projects = (from project in _acess.Getprojects() project select). Tolist(); Return Projects; }
– Tester
Cool. This is the same thing suggested in my third option. Note that as the return is Ienumerable type you do not need to use Tolist(). You probably don’t need to use this one either
from
. I just hadn’t suggested it before because it wasn’t essential to correct the mistake, which is the main subject. Hugs!– phduarte