C# 实体框架:所需的属性“;xxxxxx“;类型“”上不存在;yyyyy";
我试图从2个DBContext中提取数据,每个DBContext指向不同的数据库C# 实体框架:所需的属性“;xxxxxx“;类型“”上不存在;yyyyy";,c#,asp.net,entity-framework,C#,Asp.net,Entity Framework,我试图从2个DBContext中提取数据,每个DBContext指向不同的数据库 public class Dal : IDal { private DMECEntities _db; private DMEC_interfaceEntities _dbi; public Dal() { _db = new DMECEntities(); _dbi = new DMEC_interfaceEntities(); } }
public class Dal : IDal
{
private DMECEntities _db;
private DMEC_interfaceEntities _dbi;
public Dal()
{
_db = new DMECEntities();
_dbi = new DMEC_interfaceEntities();
}
}
然后是函数:
public List<string> GetMenuContrats(string l)
{
var mc = (
from menuc in _dbi.Menu_contrat
join ia in _db.GetIlotsAutorises(l) on menuc.contrat equals ia.ilots
select menuc
);
...
}
但是当我查看实体时,我可以找到所需的属性public Nullable date\u remise\u PV\u CEA{get;set;}
:
//------------------------------------------------------------------------------
// <auto-generated>
// Ce code a été généré à partir d'un modèle.
//
// Des modifications manuelles apportées à ce fichier peuvent conduire à un comportement inattendu de votre application.
// Les modifications manuelles apportées à ce fichier sont remplacées si le code est régénéré.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AssystMaint.Models
{
using System;
using System.Collections.Generic;
public partial class dossier_compte_rendu
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public dossier_compte_rendu()
{
this.Affectation_drt_famille = new HashSet<Affectation_drt_famille>();
this.CR_fiche_suivi_des_fréons = new HashSet<CR_fiche_suivi_des_fréons>();
this.Dossier_compte_rendu_liste_des_documents_annexes = new HashSet<Dossier_compte_rendu_liste_des_documents_annexes>();
this.DRT_intervenants = new HashSet<DRT_intervenants>();
this.drt_suivi_dechet = new HashSet<drt_suivi_dechet>();
this.Huile_remplacées_sur_OM = new HashSet<Huile_remplacées_sur_OM>();
this.Indice_des_DRT = new HashSet<Indice_des_DRT>();
this.nqs_liste_mat = new HashSet<nqs_liste_mat>();
this.nqs_liste_presta = new HashSet<nqs_liste_presta>();
this.OutillagesDRT = new HashSet<OutillagesDRT>();
this.Pièces_remplacées_sur_OM = new HashSet<Pièces_remplacées_sur_OM>();
this.Prestations_compte_rendu = new HashSet<Prestations_compte_rendu>();
this.RFI = new HashSet<RFI>();
this.syntheses_drt = new HashSet<syntheses_drt>();
this.visites_drt = new HashSet<visites_drt>();
}
public int N__OM { get; set; }
public string OTP { get; set; }
public Nullable<int> N__devis { get; set; }
public Nullable<int> Détail_matériel_n_ { get; set; }
public Nullable<int> N__batiment { get; set; }
public Nullable<int> N__local_sous_ilot { get; set; }
public string DRT_émis_sur { get; set; }
public Nullable<System.DateTime> DateRFIPrev { get; set; }
public Nullable<System.DateTime> DateRFI { get; set; }
public bool DOSSIER_DOLDE { get; set; }
public int ETAT_DU_DOSSIER { get; set; }
public bool DOSSIER_AVEC_ANOMALIE { get; set; }
public Nullable<bool> QUANTITEE_DE_FNC { get; set; }
public bool CONFORMITE_DOSSIER { get; set; }
public Nullable<bool> CONFORMITE_INTERVENTION { get; set; }
public bool MODIF_GAMME { get; set; }
public bool CR_MODIF_GAMME { get; set; }
public string CONTROLE_EXTERNE { get; set; }
public string VERIFICATION { get; set; }
public string QUALITE { get; set; }
public string SECURITE { get; set; }
public string Surveillance_client { get; set; }
public string Téléphonne_surveillance { get; set; }
public Nullable<int> CODE_VISITE { get; set; }
public string INTERVENTION { get; set; }
public string TYPE_FORTUIT { get; set; }
public string CATEGORIE_INTERVENTION { get; set; }
public string OI { get; set; }
public string OS { get; set; }
public string DI { get; set; }
public string Activité { get; set; }
public string COMMANDE_FORTUITE_N_ { get; set; }
public Nullable<int> N__LDA { get; set; }
public Nullable<int> GammeNQS { get; set; }
public Nullable<System.DateTime> date_de_saisie { get; set; }
public string Rédacteur { get; set; }
public string Vérificateur { get; set; }
public string Aprobateur { get; set; }
public Nullable<decimal> temps_prévisionnel { get; set; }
public Nullable<int> semaine { get; set; }
public Nullable<int> numéro_de_courrier { get; set; }
public System.DateTime Date_de_réalisation { get; set; }
public string Commentaires { get; set; }
public string ACT_OM { get; set; }
public string NATURE { get; set; }
public string N__DOSSIER { get; set; }
public bool INCO { get; set; }
public Nullable<int> N__de_document_mères { get; set; }
public Nullable<int> N__Analyse_risque_sureté { get; set; }
public Nullable<decimal> Dosimétrie_prévisionnelle { get; set; }
public bool Vérification_DRT_avant_travaux { get; set; }
public bool Assiter_réunion_enclenchement { get; set; }
public bool Proposition_traitement_FNC { get; set; }
public bool Vérification_DSI_renseigné { get; set; }
public bool Vérification_du_RFI { get; set; }
public decimal Montant_facturation { get; set; }
public decimal Prime_IPS { get; set; }
public Nullable<decimal> Montant_pièces { get; set; }
public Nullable<decimal> Montant_st_traitance { get; set; }
public string Mallette_outillage { get; set; }
public bool DRT_facturé { get; set; }
public bool Exclusion { get; set; }
public Nullable<int> CPT { get; set; }
public Nullable<int> BR { get; set; }
public string Poste_BR { get; set; }
public string Type_DRT { get; set; }
public bool Facturation_DRT { get; set; }
public bool CCE { get; set; }
public bool Fact_bordereau { get; set; }
public string Devis { get; set; }
public Nullable<decimal> Tps_max { get; set; }
public bool Limit { get; set; }
public bool Remis { get; set; }
public Nullable<decimal> tx_horaire { get; set; }
public string CR { get; set; }
public bool FM { get; set; }
public Nullable<int> rtr { get; set; }
public Nullable<System.DateTime> date_archive { get; set; }
public bool rex { get; set; }
public decimal Montant_remise { get; set; }
public Nullable<System.DateTime> date_remise_PV_CEA { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Affectation_drt_famille> Affectation_drt_famille { get; set; }
public virtual Analyse_de_risque_sureté Analyse_de_risque_sureté { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CR_fiche_suivi_des_fréons> CR_fiche_suivi_des_fréons { get; set; }
public virtual Création_dossiers Création_dossiers { get; set; }
public virtual Documents_de_suivi_mère Documents_de_suivi_mère { get; set; }
public virtual PV_poste PV_poste { get; set; }
public virtual RTR RTR1 { get; set; }
public virtual LDA LDA { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Dossier_compte_rendu_liste_des_documents_annexes> Dossier_compte_rendu_liste_des_documents_annexes { get; set; }
public virtual Sous_îlots_locaux Sous_îlots_locaux { get; set; }
public virtual drt_cr drt_cr { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<DRT_intervenants> DRT_intervenants { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<drt_suivi_dechet> drt_suivi_dechet { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Huile_remplacées_sur_OM> Huile_remplacées_sur_OM { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Indice_des_DRT> Indice_des_DRT { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<nqs_liste_mat> nqs_liste_mat { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<nqs_liste_presta> nqs_liste_presta { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OutillagesDRT> OutillagesDRT { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Pièces_remplacées_sur_OM> Pièces_remplacées_sur_OM { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Prestations_compte_rendu> Prestations_compte_rendu { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<RFI> RFI { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<syntheses_drt> syntheses_drt { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<visites_drt> visites_drt { get; set; }
}
}
//------------------------------------------------------------------------------
//
但在他的帖子里,他只是有一个名字问题。我的情况可能接近于此,但我不知道是什么导致了这个错误
有人能发现我不懂的东西吗
编辑1:
@DavidG实际上没有,我只有一个dbo.dossier\u compte\u rendu表,由第一个DbContext\u db指向。
第二个dbcontextu dbi指向第二个数据库,只填充指向第一个数据库中的表的视图。有几个模式,这就是为什么我有多个同名的类的原因,我只是从EF导入了所有的表和视图。以下是我制作的一些截图:
如您所见,EF生成多个类,但添加1、2。。。在名字的末尾。这可能是问题的根源吗?我认为您在这里遇到了一些令人困惑的模型命名问题。看起来你有两门课叫dossier\u compte\u rendu
?我编辑来回答你
//------------------------------------------------------------------------------
// <auto-generated>
// Ce code a été généré à partir d'un modèle.
//
// Des modifications manuelles apportées à ce fichier peuvent conduire à un comportement inattendu de votre application.
// Les modifications manuelles apportées à ce fichier sont remplacées si le code est régénéré.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AssystMaint.Models
{
using System;
using System.Collections.Generic;
public partial class dossier_compte_rendu
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public dossier_compte_rendu()
{
this.Affectation_drt_famille = new HashSet<Affectation_drt_famille>();
this.CR_fiche_suivi_des_fréons = new HashSet<CR_fiche_suivi_des_fréons>();
this.Dossier_compte_rendu_liste_des_documents_annexes = new HashSet<Dossier_compte_rendu_liste_des_documents_annexes>();
this.DRT_intervenants = new HashSet<DRT_intervenants>();
this.drt_suivi_dechet = new HashSet<drt_suivi_dechet>();
this.Huile_remplacées_sur_OM = new HashSet<Huile_remplacées_sur_OM>();
this.Indice_des_DRT = new HashSet<Indice_des_DRT>();
this.nqs_liste_mat = new HashSet<nqs_liste_mat>();
this.nqs_liste_presta = new HashSet<nqs_liste_presta>();
this.OutillagesDRT = new HashSet<OutillagesDRT>();
this.Pièces_remplacées_sur_OM = new HashSet<Pièces_remplacées_sur_OM>();
this.Prestations_compte_rendu = new HashSet<Prestations_compte_rendu>();
this.RFI = new HashSet<RFI>();
this.syntheses_drt = new HashSet<syntheses_drt>();
this.visites_drt = new HashSet<visites_drt>();
}
public int N__OM { get; set; }
public string OTP { get; set; }
public Nullable<int> N__devis { get; set; }
public Nullable<int> Détail_matériel_n_ { get; set; }
public Nullable<int> N__batiment { get; set; }
public Nullable<int> N__local_sous_ilot { get; set; }
public string DRT_émis_sur { get; set; }
public Nullable<System.DateTime> DateRFIPrev { get; set; }
public Nullable<System.DateTime> DateRFI { get; set; }
public bool DOSSIER_DOLDE { get; set; }
public int ETAT_DU_DOSSIER { get; set; }
public bool DOSSIER_AVEC_ANOMALIE { get; set; }
public Nullable<bool> QUANTITEE_DE_FNC { get; set; }
public bool CONFORMITE_DOSSIER { get; set; }
public Nullable<bool> CONFORMITE_INTERVENTION { get; set; }
public bool MODIF_GAMME { get; set; }
public bool CR_MODIF_GAMME { get; set; }
public string CONTROLE_EXTERNE { get; set; }
public string VERIFICATION { get; set; }
public string QUALITE { get; set; }
public string SECURITE { get; set; }
public string Surveillance_client { get; set; }
public string Téléphonne_surveillance { get; set; }
public Nullable<int> CODE_VISITE { get; set; }
public string INTERVENTION { get; set; }
public string TYPE_FORTUIT { get; set; }
public string CATEGORIE_INTERVENTION { get; set; }
public string OI { get; set; }
public string OS { get; set; }
public string DI { get; set; }
public string Activité { get; set; }
public string COMMANDE_FORTUITE_N_ { get; set; }
public Nullable<int> N__LDA { get; set; }
public Nullable<int> GammeNQS { get; set; }
public Nullable<System.DateTime> date_de_saisie { get; set; }
public string Rédacteur { get; set; }
public string Vérificateur { get; set; }
public string Aprobateur { get; set; }
public Nullable<decimal> temps_prévisionnel { get; set; }
public Nullable<int> semaine { get; set; }
public Nullable<int> numéro_de_courrier { get; set; }
public System.DateTime Date_de_réalisation { get; set; }
public string Commentaires { get; set; }
public string ACT_OM { get; set; }
public string NATURE { get; set; }
public string N__DOSSIER { get; set; }
public bool INCO { get; set; }
public Nullable<int> N__de_document_mères { get; set; }
public Nullable<int> N__Analyse_risque_sureté { get; set; }
public Nullable<decimal> Dosimétrie_prévisionnelle { get; set; }
public bool Vérification_DRT_avant_travaux { get; set; }
public bool Assiter_réunion_enclenchement { get; set; }
public bool Proposition_traitement_FNC { get; set; }
public bool Vérification_DSI_renseigné { get; set; }
public bool Vérification_du_RFI { get; set; }
public decimal Montant_facturation { get; set; }
public decimal Prime_IPS { get; set; }
public Nullable<decimal> Montant_pièces { get; set; }
public Nullable<decimal> Montant_st_traitance { get; set; }
public string Mallette_outillage { get; set; }
public bool DRT_facturé { get; set; }
public bool Exclusion { get; set; }
public Nullable<int> CPT { get; set; }
public Nullable<int> BR { get; set; }
public string Poste_BR { get; set; }
public string Type_DRT { get; set; }
public bool Facturation_DRT { get; set; }
public bool CCE { get; set; }
public bool Fact_bordereau { get; set; }
public string Devis { get; set; }
public Nullable<decimal> Tps_max { get; set; }
public bool Limit { get; set; }
public bool Remis { get; set; }
public Nullable<decimal> tx_horaire { get; set; }
public string CR { get; set; }
public bool FM { get; set; }
public Nullable<int> rtr { get; set; }
public Nullable<System.DateTime> date_archive { get; set; }
public bool rex { get; set; }
public decimal Montant_remise { get; set; }
public Nullable<System.DateTime> date_remise_PV_CEA { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Affectation_drt_famille> Affectation_drt_famille { get; set; }
public virtual Analyse_de_risque_sureté Analyse_de_risque_sureté { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CR_fiche_suivi_des_fréons> CR_fiche_suivi_des_fréons { get; set; }
public virtual Création_dossiers Création_dossiers { get; set; }
public virtual Documents_de_suivi_mère Documents_de_suivi_mère { get; set; }
public virtual PV_poste PV_poste { get; set; }
public virtual RTR RTR1 { get; set; }
public virtual LDA LDA { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Dossier_compte_rendu_liste_des_documents_annexes> Dossier_compte_rendu_liste_des_documents_annexes { get; set; }
public virtual Sous_îlots_locaux Sous_îlots_locaux { get; set; }
public virtual drt_cr drt_cr { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<DRT_intervenants> DRT_intervenants { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<drt_suivi_dechet> drt_suivi_dechet { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Huile_remplacées_sur_OM> Huile_remplacées_sur_OM { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Indice_des_DRT> Indice_des_DRT { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<nqs_liste_mat> nqs_liste_mat { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<nqs_liste_presta> nqs_liste_presta { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OutillagesDRT> OutillagesDRT { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Pièces_remplacées_sur_OM> Pièces_remplacées_sur_OM { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Prestations_compte_rendu> Prestations_compte_rendu { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<RFI> RFI { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<syntheses_drt> syntheses_drt { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<visites_drt> visites_drt { get; set; }
}
}