I try to retrieve a list from the data base. However when I call the ToList() method it throws and exception.Knowing that the database is not empty.
var listeRef = from r in db.refAnomalies
select r;
rapportAnomalie rp = new rapportAnomalie();
List<refAnomalie> listeRefference = listeRef.ToList();
The exception : {"Invalid column name 'rapportAnomalie_code_rapport'."}
this is my database tables:
CREATE TABLE [dbo].[refAnomalie] (
[code_anomalie] INT IDENTITY (1, 1) NOT NULL,
[libelle_anomalie] NVARCHAR (100) NOT NULL,
[score_anomalie] INT NOT NULL,
[classe_anomalie] NVARCHAR (100) NOT NULL,
CONSTRAINT [PK_dbo.refAnomalie] PRIMARY KEY CLUSTERED ([code_anomalie] ASC)
);
CREATE TABLE [dbo].[rapportAnomalie] (
[code_rapport] INT IDENTITY (1, 1) NOT NULL,
[date_rapport] DATETIME NOT NULL,
[etat] NVARCHAR (50) NOT NULL,
[code_agence] INT NOT NULL,
CONSTRAINT [PK_dbo.rapportAnomalie] PRIMARY KEY CLUSTERED ([code_rapport] ASC),
CONSTRAINT [FK_dbo.rapportAnomalie_dbo.agence_code_agence] FOREIGN KEY ([code_agence]) REFERENCES [dbo].[agence] ([code_agence]) ON DELETE CASCADE
);
GO
CREATE NONCLUSTERED INDEX [IX_code_agence]
ON [dbo].[rapportAnomalie]([code_agence] ASC);
rapportAnomalie Class :
[Table("rapportAnomalie")]
public partial class rapportAnomalie
{
[Key]
public int code_rapport { get; set; }
public DateTime date_rapport { get; set; }
[Required]
[StringLength(50)]
public string etat { get; set; }
public int code_agence { get; set; }
[ForeignKey("code_agence")]
public agence agence { get; set; }
public List<refAnomalie> listeRefAnomalie { get; set; }
public List<ligneRapportAnomalie> listeLigneRapportAnomalie { get; set; }
}
}
Anyone knows how to fix it?