2
I am trying to bring data of the materials with the data of your relationships with the Unit and TD tables, 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 results. 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'~'
What data is already included in the database? Which
String
you are using for research?– Leonel Sanches da Silva
I have over 600 items in the database in the Material table, I am searching a material I am sure has in the database, and as I said, when I take out the Include it brings the result correctly but without the data from TD and Drive.
– Alan Almeida
Try to take the query generated by doing the following:
var stringTeste = (from x in db.Material.Include("Unidade").Include("TD").Where(x => x.Nome.Contains(Nome))).ToString()
. Put theString
generated in SQL Server Management Studio and see what happens.– Leonel Sanches da Silva
the error string, Must declare scalar variable @p__linq_0, see, updated my question and posted the generated SQL code.
– Alan Almeida
Even if I replace the parameter with a material name SQL Server does not return anything to me.
– Alan Almeida