Partage
  • Partager sur Facebook
  • Partager sur Twitter

L'expression de propriété n'est pas valide EF

L'expression de propriété n'est pas valide EntityFramework

Sujet résolu
    13 mars 2019 à 10:17:03

    Bonjour la communauté,

    J'ai l'erreur suivante:

    {"L'expression de propriété 'e => new VB$AnonymousType_0`3(CodeSociete = e.CodeSociete, CodeCentrale = e.CodeCentrale, NoBL = e.NoBl)' n'est pas valide. L'expression doit représenter une propriété : C#: 't => t.MyProperty'  VB.Net: 'Function(t) t.MyProperty'. En spécifiant plusieurs propriétés, utilisez un type anonyme : C#: 't => new { t.MyProperty1, t.MyProperty2 }'  VB.Net: 'Function(t) New With { t.MyProperty1, t.MyProperty2 }'."}

    Comme si je n'utilise pas des propriétés alors que je vous montre mes classes:

    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel.DataAnnotations
    Imports System.ComponentModel.DataAnnotations.Schema
    Imports System.Data.Entity.Spatial
    
    <Table("BonlivRisques")>
    Partial Public Class BonlivRisques
    
        <Key>
        <Column(Order:=0)>
        <StringLength(5)>
        Public Property CodeSociete As String
    
        <Key>
        <Column(Order:=1)>
        <StringLength(5)>
        Public Property CodeCentrale As String
    
        <Key>
        <Column(Order:=2)>
        <DatabaseGenerated(DatabaseGeneratedOption.None)>
        Public Property NoBL As Integer
    
        <Key>
        <Column(Order:=3)>
        <DatabaseGenerated(DatabaseGeneratedOption.None)>
        Public Property IdRisque As Integer
    
        Public Property Choix As Short?
    
        <StringLength(200)>
        Public Property Observation As String
    
        Public Property DateModif As Date?
    
        <StringLength(10)>
        Public Property Id As String
    
        Public Property Convocation As Integer?
    
        Public Property Lavage As Integer?
    
        Public Property TypePrestation As Integer?
    
        Public Property LgFleche As Single?
    
        Public Property LgTuyau As Single?
    
        Public Property VisitePrealable As Short?
        Public Overridable Property Bonliv As BonLiv
    End Class
    
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel.DataAnnotations
    Imports System.ComponentModel.DataAnnotations.Schema
    Imports System.Data.Entity.Spatial
    
    <Table("BonLiv")>
    Partial Public Class BonLiv
        Public Sub New()
            BonlivRisques = New HashSet(Of BonlivRisques)()
        End Sub
        <Key>
        <Column(Order:=0)>
        <StringLength(5)>
        Public Property CodeSociete As String
    
        <Key>
        <Column(Order:=1)>
        <StringLength(5)>
        Public Property CodeCentrale As String
    
        <Key>
        <Column(Order:=2)>
        <DatabaseGenerated(DatabaseGeneratedOption.None)>
        Public Property NoBl As Integer
    
        Public Property Blproduit As Short?
    
        Public Property BlPrefa As Short?
    
        Public Property BLCarriere As Short?
    
        Public Property BlDechets As Short?
    
        Public Property BLTransfert As Short?
    
        Public Property BLTop As Short?
    
        Public Property BLRefuse As Short?
    
        <StringLength(5)>
        Public Property CodeRegion As String
    
        <StringLength(20)>
        Public Property CodeCmd As String
    
        Public Property NoDevis As Integer?
    
        Public Property DateFab As Date?
    
        Public Property DateLivr As Date?
    
        <StringLength(10)>
        Public Property CodeClient As String
    
        <StringLength(10)>
        Public Property CodeChantier As String
    
        <StringLength(10)>
        Public Property CodeFormule As String
    
        <StringLength(10)>
        Public Property IdRecette As String
    
        <StringLength(10)>
        Public Property CodeProduit As String
    
        Public Property TourneeMortier As Short?
    
        <StringLength(15)>
        Public Property NoTournee As String
    
        Public Property TourneMortier As Short?
    
        Public Property Grave As Short?
    
        <StringLength(10)>
        Public Property CodeVehicule As String
    
        <StringLength(10)>
        Public Property CodeChauffeur As String
    
        <StringLength(10)>
        Public Property CodeBenne As String
    
        <StringLength(5)>
        Public Property CodeZoneLivr As String
    
        <StringLength(5)>
        Public Property CodeZoneFac As String
    
        Public Property FactIncomplet As Short?
    
        Public Property QteIncomplet As Single?
    
        Public Property FinDeCoulage As Short?
    
        Public Property FactComplet As Short?
    
        Public Property FactHeureAtt As Short?
    
        Public Property QteFab As Single?
    
        Public Property QteLivr As Single?
    
        Public Property QteAccep As Single?
    
        <StringLength(5)>
        Public Property CodeUniteLiv As String
    
        Public Property QteOrigine As Single?
    
        Public Property QteRestLiv As Single?
    
        Public Property QteDejaLiv As Single?
    
        Public Property QteJete As Single?
    
        Public Property QteReplace As Single?
    
        Public Property QteProduction As Single?
    
        Public Property QteManu As Single?
    
        Public Property NoBlOrigine As Integer?
    
        Public Property NoBlReplace As Integer?
    
        <StringLength(5)>
        Public Property CodeSocBl As String
    
        <StringLength(5)>
        Public Property CodeCentBl As String
    
        Public Property HeureLivr As Date?
    
        Public Property HeureConv As Date?
    
        Public Property Reserve As Short?
    
        Public Property HeureDepCent As Date?
    
        Public Property Heure1Gachee As Date?
    
        Public Property HeureArrCht As Date?
    
        Public Property HeureDebDech As Date?
    
        Public Property HeureFinDech As Date?
    
        Public Property HeureDepCht As Date?
    
        Public Property HeureRetCent As Date?
    
        Public Property TempsAtt As Date?
    
        Public Property BlManuel As Short?
    
        Public Property NoFacture As Integer?
    
        Public Property DateFact As Date?
    
        Public Property FacturePayee As Short?
    
        Public Property PuBeton As Single?
    
        Public Property PuZone As Single?
    
        Public Property CoutZone As Single?
    
        Public Property CoutZoneForfait As Short?
    
        <StringLength(5)>
        Public Property DeviseCoutzone As String
    
        Public Property ValeurDeviseCout As Single?
    
        Public Property RemiseValeur As Short?
    
        Public Property Remisebeton As Single?
    
        Public Property NbEdition As Short?
    
        <StringLength(50)>
        Public Property CodeLibre As String
    
        Public Property Depanage As Short?
    
        <StringLength(5)>
        Public Property CodeCentraleCht As String
    
        <StringLength(5)>
        Public Property CodeCentraleProd As String
    
        <StringLength(5)>
        Public Property CodeCentraleFor As String
    
        Public Property DateTransfert As Date?
    
        Public Property TareVehicule As Single?
    
        Public Property BrutVehicule As Single?
    
        Public Property TareCamion As Single?
    
        Public Property TareBenne As Single?
    
        <StringLength(50)>
        Public Property Divers As String
    
        <StringLength(100)>
        Public Property Commentaire As String
    
        <StringLength(100)>
        Public Property Commentaire2 As String
    
        Public Property PortDu As Short?
    
        <StringLength(50)>
        Public Property LibellePortDu As String
    
        <StringLength(10)>
        Public Property BonDeCaisse As String
    
        Public Property PtrVeh As Single?
    
        Public Property PtrBenne As Single?
    
        Public Property BetonAchete As Short?
    
        <StringLength(10)>
        Public Property CodeFournisseur As String
    
        <StringLength(25)>
        Public Property Nobr As String
    
        Public Property ValeurQte As Short?
    
        <StringLength(50)>
        Public Property NoPlaque As String
    
        <StringLength(50)>
        Public Property LibTransporteur As String
    
        <StringLength(10)>
        Public Property TypeOuvrage As String
    
        <StringLength(10)>
        Public Property NatureOuvrage As String
    
        <StringLength(10)>
        Public Property ModeDechargement As String
    
        Public Property DateCrea As Date?
    
        Public Property DateModif As Date?
    
        Public Property DateSupp As Date?
    
        Public Property DateMaj As Date?
    
        <StringLength(10)>
        Public Property IdCrea As String
    
        <StringLength(10)>
        Public Property IDReprise As String
    
        <StringLength(10)>
        Public Property ID As String
    
        Public Property BlAvoir As Short?
    
        <StringLength(15)>
        Public Property NoTicket As String
    
        Public Property QuickBatch As Short?
    
        <StringLength(5)>
        Public Property CodePaysLivr As String
    
        <StringLength(5)>
        Public Property CodePaysFact As String
    
        <StringLength(5)>
        Public Property CodeLangueCht As String
    
        <StringLength(5)>
        Public Property CodeLangueClt As String
    
        Public Property PrctTixoCamion As Single?
    
        Public Property NumVariante As Short?
    
        Public Property BLComptantALOrigine As Short?
    
        Public Property Num_Precommande As Integer?
    
        Public Property Code_Pastille As Integer?
    
        <StringLength(1)>
        Public Property AttestationTva As String
    
        Public Property NumLignePCmd As Integer?
    
        Public Property AutomateTiers As Short?
    
        <StringLength(50)>
        Public Property RefCommande As String
    
        Public Property DateDepartBenne As Date?
    
        Public Property Temperature As Single?
    
        Public Property Prelevement As Short?
    
        Public Property DensiteProduit As Single?
    
        Public Property PoidsManuel As Short?
    
        Public Property RetourCertifie As Short?
    
        Public Property HeureTransport As Single?
    
        Public Property CoutHeureTransport As Single?
    
        Public Property BLGratuit As Short?
    
        <StringLength(10)>
        Public Property CodeTransporteur As String
    
        Public Property HeureFinChargement As Date?
    
        <StringLength(5)>
        Public Property CodeCentraleCmd As String
    
        Public Property DateChgt As Date?
    
        Public Property HeureChgt As Date?
    
        <StringLength(10)>
        Public Property CodeGS As String
    
        <StringLength(10)>
        Public Property CodeProvenance As String
    
        <StringLength(50)>
        Public Property CdPostalProvenance As String
    
        <StringLength(5)>
        Public Property CdPaysProvenance As String
    
        Public Property PrestationPesage As Short?
    
        Public Property ProduitDechet As Short?
    
        <StringLength(5)>
        Public Property CodeRegionVeh As String
    
        Public Property CoutTransport As Integer?
    
        Public Property HeureMiseEnOeuvre As Date?
    
        Public Property ChtConnuAdrModifie As Short?
    
        Public Property TraitementGPS As Integer?
    
        Public Property AchatExtNonCertifie As Short?
    
        Public Property CadencementM3Heure As Single?
    
        <StringLength(50)>
        Public Property TelContact As String
    
        <StringLength(50)>
        Public Property NomContact As String
    
        <StringLength(10)>
        Public Property CodeAgence As String
    
        <StringLength(10)>
        Public Property CodeClientFinal As String
    
        <StringLength(50)>
        Public Property NomClientFinal As String
    
        Public Property BLComposant As Short?
    
        Public Property NumContratSAP As Integer?
    
        Public Property NumLigneCtFor As Integer?
    
        Public Property TransportTiersExt As Short?
    
        Public Property IdBLRetour As Integer?
    
        <StringLength(10)>
        Public Property ZoneTransportEBM As String
    
        Public Property KmFacture As Single?
    
        Public Property KMReel As Single?
    
        <StringLength(69)>
        Public Property ConcreteFireQ As String
    
        <StringLength(69)>
        Public Property AggregateCodeFireQ As String
    
        <StringLength(20)>
        Public Property ConcreteSAP As String
    
        <StringLength(16)>
        Public Property AggregateCodeSAP As String
    
        <StringLength(10)>
        Public Property CodeVehiculePM As String
    
        Public Property QuantitePM As Single?
    
        Public Property TempsAllerPM As Date?
    
        Public Property TempsRetourPM As Date?
    
        Public Property NormeNF As Short?
    
        <StringLength(250)>
        Public Property CaracteresNF As String
    
        Public Property IdNorme As Integer?
    
        <StringLength(250)>
        Public Property CheminLogo As String
    
        Public Property LiantEquiv As Single?
    
        Public Property QteLiantAdj As Single?
    
        <StringLength(10)>
        Public Property CodeAffreteur As String
    
        <StringLength(50)>
        Public Property NomOrganismeCertif As String
    
        <StringLength(250)>
        Public Property CommentaireChauffeur As String
    
        Public Property StationEau As Single?
    
        <StringLength(10)>
        Public Property Code_Categ_Planning As String
    
        Public Property EBM_Propriete As Integer?
    
        <StringLength(50)>
        Public Property EBM_NoPlaque1 As String
    
        <StringLength(50)>
        Public Property EBM_NoPlaque2 As String
    
        Public Property EBM_Surcharge As Short?
    
        Public Property EBM_TareEnsemble1 As Single?
    
        Public Property EBM_PtcaEnsemble1 As Single?
    
        Public Property EBM_TareEnsemble2 As Single?
    
        Public Property EBM_PtcaEnsemble2 As Single?
    
        Public Property EBM_RemiseTarif As Single?
    
        Public Property EBM_RemiseTarifPrct As Short?
    
        <StringLength(10)>
        Public Property EBM_RefShipTo As String
    
        <StringLength(100)>
        Public Property EBM_LibelleFormuleMaroc As String
    
        Public Property PropComHB_NoOffre As Integer?
    
        <StringLength(10)>
        Public Property PropComHB_IdCreateur As String
    
        <StringLength(5)>
        Public Property PropComHB_CodeCentrale As String
    
        Public Property MtAjoutEau As Single?
    
        Public Property MTWaterRelease As Short?
    
        <Column(TypeName:="text")>
        Public Property MTCommentaireChf As String
    
        <Column(TypeName:="text")>
        Public Property MTCommentaireClt As String
    
        <Column(TypeName:="text")>
        Public Property MTCommentaireAdd As String
    
        Public Property MTDommageLiv As Short?
    
        Public Property VehRenfort As Short?
    
        <StringLength(20)>
        Public Property VehRenfortPlaque As String
    
        Public Property NbKilometre As Single?
    
        <StringLength(10)>
        Public Property MTModeDechargement As String
    
        Public Property MtRetourBeton As Single?
    
        <StringLength(10)>
        Public Property NoDSD As String
    
        Public Property SansImpPesees As Short?
    
        Public Property DateRFID As Date?
    
        Public Property HeureEntreeMp As Date?
    
        <StringLength(10)>
        Public Property CodeChantierDestination As String
    
        Public Property ModeES As Short?
    
        Public Property ModeE As Short?
    
        Public Property typeBL As Short?
    
        Public Property SurchagePontBascule As Short?
    Public Overridable Property BonlivRisques As ICollection(Of BonlivRisques)
    End Class
    

    Et voici comment je fais ma liaison:

            modelBuilder.Entity(Of BonLiv)() _
                .HasMany(Function(e) e.BonlivRisques) _
                .WithRequired(Function(e) e.Bonliv) _
                .HasForeignKey(Function(e) New With {e.CodeSociete, e.CodeCentrale, e.NoBL}) _
                .WillCascadeOnDelete(False)

    j'ai énormément de liaisons simple comme celle-ci qui fonctionne très bien et je ne comprend pas mon erreur.

    Une idée?




    • Partager sur Facebook
    • Partager sur Twitter
    Si vous ne réussissez pas du premier coup, appelez ça « version 1.0 ».
      15 juillet 2019 à 16:58:12

      Bonjour la communauté,

      J'ai compris que la liaison ne fonctionne pas si les propriétés qui composes la liaison ne sont pas dans le même ordre dans les classes entre elles et dans la liaison.

      a+

      • Partager sur Facebook
      • Partager sur Twitter
      Si vous ne réussissez pas du premier coup, appelez ça « version 1.0 ».

      L'expression de propriété n'est pas valide EF

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown