Is it possible to make a related Entity possible to be displayed with Odata Expand (WebApi)?

1

Hello, I have a question regarding the following situation: I have an Entity that I defined in my model as TaskFreq

public partial class TarefaFreq
{
    [Key]
    public int ID { get; set; }
    public string Name { get; set; }
}

I created some data in a static list:

public class TarefaFreqData
{
    public static IEnumerable<TarefaFreq> GetLista()
    {
        var list = new List<TarefaFreq>();
        list.Add(new TarefaFreq() { ID = 1, Name = "Teste 1" });
        list.Add(new TarefaFreq() { ID = 2, Name = "Teste 2" });            
        return list;
    }        
}

And I also have the Task model (This one is in the database):

    public partial class Tarefa
    {
        public int ID { get; set; }
        public int FreqID { get; set; } 
        public virtual TarefaFreq Freq { get; set; }
    }

In my webAPI settings with Entity-Framework if I try to set my property: builder.EntityType<Tarefa>().Property(f => f.Freq); I get the following error: The type TarefaFreq must be a non-nullable value type in order to use it ...

My goal is that when I enter in the URL: http://localhost:58170/odata/Tarefas(12)/?$expand=Freq I can get the data in the response.

Remembering that TaskFreq Entity will not be in my database, it was only created to serve data to a foreign key that is in my database which is the property of Tarefa - > FreqID , so the static list I created. In this case, as I'm developing in the client I need to use the $expand of ASP.NET Web API 2 OData.

    
asked by anonymous 26.07.2018 / 20:12

0 answers