so Iam new to code firt and I have a database that is done already and cant change and I get this error when I call clientes in my controller get this error because it look for a Empresa_id that not exist so how I can tell to look for the the correct field?
return View(clientes.ToPagedList(pageNumber, pageSize));
it return this select
SELECT
[Extent1].[id] AS [id],
[Extent1].[name] AS [name],
[Extent1].[empresa] AS [empresa],
[Extent1].[Empresa_id] AS [Empresa_id]
FROM [dbo].[cliente] AS [Extent1]
ORDER BY [Extent1].[name] ASC}
public class cliente
{
[Key]
public int id { get; set; }
public string name { get; set; }
public int empresa { get; set; } // foreing key
public virtual empresa Empresa { get; set; }
}
public class empresa
{
[Key]
public int id { get; set; }
public string descripcion { get; set; }
public virtual ICollection<cliente> Clientes { get; set; }
}
You must tell EF that
empresais the foreign key for the navigation propertyEmpresa, otherwise it will assume a default foreign key name, that is “NavigationPropertyName+UnderScore+KeyNameInTargetClass” =Empresa_id. You can overwrite this default by applying the[ForeignKey]attribute: