2017-04-26 25 views
0

我已經一直在尋找了幾天,仍然沒有找到答案匹配,所以我問你們,希望你能幫助我實體類型<entity>不機型爲當前上下文

我爲我的實習建立一個軟件,但我只是繼續其他人的代碼。問題是,2天前我用Visual Studio 2017構建了這個項目,並且它運行良好,現在它不再工作了,當我嘗試使用某些關係進行某些操作時,出現此「實體類型...」錯誤(不是全部)

舉個例子:

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

調用

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

這裏是HDPreDiag實體類

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; } 
} 

我不明白的事情是,它的工作,突然不工作了,我不明白這一點

感謝您的幫助

編輯:

FichePrediag類:

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(); 
     } 
    } 
} 
+0

有你試過[link](http://stackoverflow.com/questions/4983108/the-entity-type-classname-is-not-part-of-the-model-for-the-current-context)這個解決方案? – nocodename

+0

我試過沒有結果:/ –

+0

哪行引發實體異常?看起來你的代碼是不完整的,爲實體結構提供更多細節以及該方法應該完成什麼操作。 –

回答

0

好吧,我想通了什麼問題了,天哪,我傻的xD

我的合作改變了functionnality德,所以我不得不「nomDemandeAide」(串)更改爲列表...所以我不得不改回爲一個字符串,用相同DateTimeDemandeAide

謝謝你們的幫助:)

相關問題