0

I've already been searching for days and still didn't find the answer, so I'm asking you guys, hope you can help me

I'm building a software for my internship, but I just continue everyone else's code. The problem is, 2 days ago I built the project with Visual Studio 2017 and it worked fine, and now it doesn't work anymore, and I get this "Entity type..." error when I try to do something with some relations (not all of them)

As an example :

DAO.FichePreDiag f = BP.getFicheById(r.idFiche);

that calls

try
        {
            using (var ctx = new HDPreDiagEntities())
            {
                return ctx.FichePreDiags.Where(f => f.id == idFiche).First();
            }
        }

Here is the HDPreDiag Entities class

public partial class HDPreDiagEntities : DbContext
{
    public HDPreDiagEntities()
        : base("name=HDPreDiagEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<Equipement> Equipements { get; set; }
    public virtual DbSet<FichePreDiag> FichePreDiags { get; set; }
    public virtual DbSet<Text> Texts { get; set; }
    public virtual DbSet<TypePanne> TypePannes { get; set; }
    public virtual DbSet<User> Users { get; set; }
    public virtual DbSet<HistoriqueMail> HistoriqueMails { get; set; }
    public virtual DbSet<Pointage> Pointages { get; set; }
    public virtual DbSet<Rapport> Rapports { get; set; }
}

The thing I do not understand is that it worked and suddenly didn't work anymore, I don't get it

Thanks for your help

edit :

FichePrediag class :

public partial class FichePreDiag
{
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]

    public int id { get; set; }
    public System.DateTime DateCreation { get; set; }
    public bool telMail { get; set; }
    public string interlocuteurHD { get; set; }
    public string nomClient { get; set; }
    public string classificationClient { get; set; }
    public bool commentaireClient { get; set; }
    public bool acreerClient { get; set; }
    public bool amodifierClient { get; set; }
    public string idClient { get; set; }
    public string nomInterlocuteur { get; set; }
    public string mailInterlocuteur { get; set; }
    public string telephoneInterlocuteur { get; set; }
    public bool acreerInterlocuteur { get; set; }
    public bool amodifierInterlocuteur { get; set; }
    public string identificationHD { get; set; }
    public string typeMachine { get; set; }
    public string cn { get; set; }
    public string identificationClient { get; set; }
    public bool acreerMachine { get; set; }
    public bool etiquetteMachine { get; set; }
    public bool amodifierMachine { get; set; }
    public bool maintenancePropose { get; set; }
    public Nullable<int> numIntervention { get; set; }
    public string technicienPrecedent { get; set; }
    public Nullable<int> degresUrgence { get; set; }
    public bool majorationUrgence { get; set; }
    public string panne { get; set; }
    public string descriptif { get; set; }
    public string typeContrat { get; set; }
    public Nullable<int> nbHeure { get; set; }
    public Nullable<System.DateTime> datePropose { get; set; }
    public Nullable<System.DateTime> dateConfirmee { get; set; }
    public string dialogueClient { get; set; }
    public string Equipements { get; set; }
    public string Fournitures { get; set; }
    public bool isArchived { get; set; }
    public Nullable<System.DateTime> LastMaintenance { get; set; }
    public string idInterlocuteur { get; set; }
    public string typepanne1 { get; set; }
    public string typepanne2 { get; set; }
    public string Techniciens { get; set; }
    public Nullable<System.DateTime> NextMaintenance { get; set; }
    public string motifAppel { get; set; }
    public string cds { get; set; }
    public string bi { get; set; }
    public string statusCDS { get; set; }
    public string fonctionInterlocuteur { get; set; }
    public List<string> NomDemandeAide { get; set; }
    public List<Nullable<System.DateTime>> DateTimeDemandeAide { get; set; }
    public string NomDemandeDevis { get; set; }
    public Nullable<System.DateTime> DateTimeDemandeDevis { get; set; }
    public string nomInterlocuteurSurPlace { get; set; }
    public string fonctionInterlocuteurSurPlace { get; set; }
    public string mailInterlocuteurSurPlace { get; set; }
    public string telephoneInterlocuteurSurPlace { get; set; }
    public Nullable<System.DateTime> DatePlanificationDeb { get; set; }
    public Nullable<System.DateTime> DatePlanificationFin { get; set; }
    public Nullable<decimal> tarifBiPrice { get; set; }
    public string tarifBiNom { get; set; }

    public string telMailString { get { return (this.telMail) ? "Téléphone" : "Mail/Fax"; } }
    public string typeModifClientString { get { return (this.acreerClient) ? "A CREER" : "A MODIFIER"; } }
    public string typeModifInterlocuteurString { get { return (this.acreerInterlocuteur) ? "A CREER" : "A MODIFIER"; } }
    public string commentaireString { get { return (this.commentaireClient) ? "Oui" : "Non"; } }
    public string refMachineHD { get { return this.identificationHD.Split(' ')[0]; } }

    public bool demandeAideFilled { get { return (this.NomDemandeAide != null); } }
    public bool demandeAideFilledAndItsMine { get { return (this.NomDemandeAide != null && isMine()); } }
    public bool demandeDevisFilled { get { return (this.NomDemandeDevis != null); } }
    public bool demandeDevisFilledAndItsMine { get { return (this.NomDemandeDevis != null && DAL.getUserByUsername(Environment.UserName).fullName.Equals(this.NomDemandeDevis)); } }

    /// <summary>
    /// Fonction qui permet de vérifier si un technicien a été sollicité pour de l'aide.
    /// </summary>
    public bool isMine() {/*
        foreach(string nomTechnicien in this.NomDemandeAide) {
            if(DAL.getUserByUsername(Environment.UserName).fullName.Equals(nomTechnicien))
                return true;
        }
        return false;*/

        return this.NomDemandeAide.Contains(DAL.getUserByUsername(Environment.UserName).fullName);
    }

    /// <summary>
    /// Fonction qui permet de retirer un technicien de la liste des techniciens sollicités pour de l'aide.     
    /// </summary>
    public void removeFromHelp()
    {
        this.NomDemandeAide.Remove(DAL.getUserByUsername(Environment.UserName).fullName);
    }

    public string interlocuteurHDInitiale
    {
        get
        {
            string ret = "";
            foreach (char c in this.interlocuteurHD.ToCharArray())
            {
                if (char.IsUpper(c))
                    ret += c;
            }
            return ret;
        }
    }

    public string techniciensString
    {
        get
        {
            string ret = "";
            string[] ss = this.Techniciens.Split(';');
            for (int i = 0; i < ss.Length - 1; i++)
            {
                if (i == 0)
                    ret = ss[i];
                else if (i == ss.Length - 2)
                    ret += " et " + ss[i];
                else
                    ret += ", " + ss[i];
            }
            return ret;
        }
    }

    public string NumSuivi
    {
        get
        {
            string ret = "";
            if (id < 1000000)
            {
                ret += "0";
                if (id < 100000)
                {
                    ret += "0";
                    if (id < 10000)
                    {
                        ret += "0";
                        if (id < 1000)
                        {
                            ret += "0";
                            if (id < 100)
                            {
                                ret += "0";
                                if (id < 10)
                                    ret += "0";
                            }
                        }
                    }
                }
            }
            return ret + id.ToString();
        }
    }
}
  • Have you tried [link](http://stackoverflow.com/questions/4983108/the-entity-type-classname-is-not-part-of-the-model-for-the-current-context) this solution? – nocodename Apr 26 '17 at 07:08
  • I tried without result :/ – Jérémy Lefebvre Apr 26 '17 at 07:59
  • Which line throwing entity exception? Seems that your code is incomplete, provide more details to entity structure and what action should be done by the method. – Tetsuya Yamamoto Apr 26 '17 at 08:02
  • Can you provide `FichePreDiag` entity class and it's mapping? – nocodename Apr 26 '17 at 08:02
  • Entity Exception is thrown by the "return ctx.FichePreDiags..." line in try This method is supposed to return a "FichePreDiag" entity by its id, but every method that try to return something from the FichePreDiag relation throw an Entity exception I also edited my post to add the FichePreDiag class – Jérémy Lefebvre Apr 26 '17 at 08:45
  • Is there need for the entity class to be partial? And if so, are you sure, the extension of it is in the same namespace? Also, what EF version are you using? – nocodename Apr 26 '17 at 09:17
  • I'm using EF 6.1.3, and since I didn't write that code in the first place (I'm supposed to improve it..) I don't really know if the entity class needs to be partial.. – Jérémy Lefebvre Apr 26 '17 at 09:30
  • edit : It looks like it doesn't need to be partial, does it help ? – Jérémy Lefebvre Apr 26 '17 at 09:41
  • 1
    With EF 6.1.3 not really. Are you using Code First approach? And did you double checked if the model matches exactly what you have in db table? It seems like something isn't mapping as it used to. – nocodename Apr 26 '17 at 09:47
  • So if you're using Code First, try executing Add-Migration command and see if EF detecting any changes in model. If so, there maybe some mappings tweaking needed. – nocodename Apr 26 '17 at 10:05

1 Answers1

0

Okay I figured out what the problem was, god I'm stupid xD

I changed a functionnality in the code, so I had to change "nomDemandeAide" (string) to a List... So I just had to change it back to a string, same with DateTimeDemandeAide

Thank you guys for your help :)