首页 > 解决方案 > 实体框架:类型“yyyyyy”上不存在所需的属性“xxxxxx”

问题描述

我正在尝试从 2 个 DbContexts 中提取数据,每个 DbContexts 指向不同的数据库。

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

因此,当我运行我的应用程序时,出现以下错误:

The relationship 'DMECModel.FK_visites_drt_dossier_compte_rendu' was not loaded because the type 'DMECModel.dossier_compte_rendu' is not available.
The following information may be useful in resolving the previous error:
The required property 'date_remise_PV_CEA' does not exist on the type 'AssystMaint.Models.dossier_compte_rendu'.

但是当我查看我的实体时,我可以找到所需的属性public Nullable<System.DateTime> date_remise_PV_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} 上不存在所需的属性 {0}。添加 FK 时的实体框架(模型优先)

但在他的线程中,他只是有一个名字问题。我的情况可能与此接近,但我无法弄清楚是什么导致了该错误。

有人能发现我不明白的地方吗?

编辑 1:

@DavidG实际上没有,我只有第一个 DbContext _db 指向的 dbo.dossier_compte_rendu 表。第二个 DbContext _dbi 指向第二个数据库,仅填充指向第一个数据库中表的视图。有几个模式,所以这就是为什么我有多个具有相似名称的类的解释,我只是从 EF 导入了所有表和视图。这是我制作的一些屏幕截图:

在此处输入图像描述

如您所见,EF 生成多个类,但在名称末尾添加 1、2...。有可能是问题的根源吗?

标签: c#asp.netentity-framework

解决方案


推荐阅读