I'm trying to get data from the materials with the data of your relationships with the tables Unit and TD, but this code below does not return anything, if I do without Include () it returns the data but with the relationship does not bring any result . In the Material class I have the navigation properties for Unit and TD.
public IEnumerable<Material> Listar(String Nome)
{
IEnumerable<Material> materiais = (from x in db.Material
.Include("Unidade")
.Include("TD")
.Where(x => x.Nome.Contains(Nome)) select x).ToList();
return materiais;
}
SQL code generated by Entity:
SELECT
[Extent1].[ID] AS [ID],
[Extent1].[CodTron] AS [CodTron],
[Extent1].[RefTron] AS [RefTron],
[Extent1].[Nome] AS [Nome],
[Extent1].[UnidadeID] AS [UnidadeID],
[Extent1].[TDID] AS [TDID],
[Extent2].[ID] AS [ID1],
[Extent2].[CodTron] AS [CodTron1],
[Extent2].[Referencia] AS [Referencia],
[Extent2].[Descricao] AS [Descricao],
[Extent2].[Simbolo] AS [Simbolo],
[Extent3].[ID] AS [ID2],
[Extent3].[Numero] AS [Numero],
[Extent3].[Descricao] AS [Descricao1],
[Extent3].[RefTron] AS [RefTron1]
FROM [dbo].[Material] AS [Extent1]
INNER JOIN [dbo].[Unidade] AS [Extent2] ON [Extent1].[UnidadeID] = [Extent2].[ID]
INNER JOIN [dbo].[TD] AS [Extent3] ON [Extent1].[TDID] = [Extent3].[ID]
WHERE [Extent1].[Nome] LIKE @p__linq__0 ESCAPE N'~'