1
Hello, I have a question regarding the following situation: I have an Entity that I defined in my model as Tasfafreq
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 the settings of my webAPI 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 report to the URL:
http://localhost:58170/odata/Tarefas(12)/?$expand=Freq
I can get the data in the answer.
Recalling that the Taskforce Entity will not be in my database, it has only been created to serve data to a foreign key that is in my database that is owned by Tarefa
-> FreqID
, so the static list I created. In this case, as I am developing in the client I need to use the $expand
of ASP.NET Web API 2 Odata.
Ever tried to turn into
struct
? I’m not familiar with these requirements of the tool, but this should solve it. I’m just not saying it’s the right solution. Is it right there not only to use theID
of the object? It even seems. It even seems to be something redundant in the code.– Maniero
@Maniero Good, as it is so far, is working when I need to create the relationship between the foreign key and the data on my list. The
$expand
to the entity thatTarefaFreq
is that when I list the details this information cannot come mapped in the field.– Wesley Heron