olive2634  | Bonjour,
 je suis en train d'effectuer le mapping de ma base de données avec le framework NHibernate sous Visual Studio 2008.
 Je posséde une table "Contrat" qui est associé à une table "Client" et une table "Interimaire".   La table "Contrat" possède donc une clef primaire composé de :             - numContrat
           - numClient
           - matricule (interimaire)
   mon fichier de mapping est le suivant :    
  
 <?xml version="1.0" encoding="utf-8"?>
 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <!--Built with MyGeneration/Template/NHibernate (c) by OHM (alvy77@hotmail.com)
 based on NHibernate lujan99 0.9.20 (c) by lujan99@usa.net-->
   <class name="adecco.Entities.Contrat,adecco" table="contrat" lazy="false">
         <composite-id name="Id" class="adecco.Entities.ContratId,adecco">
       <key-property name="NumContrat" column="num_contrat" type="int" />
       <key-property name="ClientNumClient" column="client_num_client" type="int" />
       <key-property name="InterimaireMatricule" column="interimaire_matricule" type="int" />
     </composite-id>
       <property type="int" not-null="true" name="TypeAvenantId" column="[type_avenant_id]" />
     <property type="int" not-null="true" name="QualificationId" column="[qualification_id]" />
     <property type="int" not-null="true" name="StatutContratId" column="[statut_contrat_id]" />
     <property type="DateTime" not-null="true" name="DateAvenant" column="[date_avenant]" />
     <property type="bool" not-null="true" name="TacheRisque" column="[tache_risque]" />
     <property type="bool" not-null="true" name="Intemperie" column="[intemperie]" />
     <property type="bool" not-null="true" name="Risque" column="[risque]" />
     <property type="bool" not-null="true" name="SurveillanceMedical" column="[surveillance_medical]" />
     </class>
 </hibernate-mapping>
   |  
 
   Je vais maintenant vous présenter la classe Entity "ContratID.cs" :    
  
   et bien sur la classe Entity "contrat.cs" :    
  Code :
 - /*
 - using MyGeneration/Template/NHibernate (c) by OHM (alvy77@hotmail.com)
 - based on NHibernate lujan99 0.9.20 (c) by lujan99@usa.net
 - */
 - using System;
 - using System.Collections;
 - using System.Collections.Generic;
 - using adecco.Entities;
 - namespace adecco.Entities
 - {
 -     /// <summary>
 -     /// IContrat interface for NHibernate mapped table 'contrat'.
 -     /// </summary>
 -     public interface IContrat
 -     {
 -         #region Public Properties
 -         ContratId Id
 -         {
 -             get;
 -             set;
 -         }
 -         int TypeAvenantId
 -         {
 -             get;
 -             set;
 -         }
 -         int QualificationId
 -         {
 -             get;
 -             set;
 -         }
 -         int StatutContratId
 -         {
 -             get;
 -             set;
 -         }
 -         DateTime DateAvenant
 -         {
 -             get;
 -             set;
 -         }
 -         bool TacheRisque
 -         {
 -             get;
 -             set;
 -         }
 -         bool Intemperie
 -         {
 -             get;
 -             set;
 -         }
 -         bool Risque
 -         {
 -             get;
 -             set;
 -         }
 -         bool SurveillanceMedical
 -         {
 -             get;
 -             set;
 -         }
 -         bool IsDeleted { get; set; }
 -         bool IsChanged { get; set; }
 -         #endregion
 -     }
 -     /// <summary>
 -     /// Contrat object for NHibernate mapped table 'contrat'.
 -     /// </summary>
 -     [Serializable]
 -     public class Contrat : IContrat
 -     {
 -         #region Member Variables
 -         protected ContratId id;
 -         protected int typeavenantid;
 -         protected int qualificationid;
 -         protected int statutcontratid;
 -         protected DateTime dateavenant;
 -         protected bool tacherisque;
 -         protected bool intemperie;
 -         protected bool risque;
 -         protected bool surveillancemedical;
 -         protected bool _bIsDeleted;
 -         protected bool _bIsChanged;
 -         #endregion
 -         #region Constructors
 -         public Contrat() { }
 -         public Contrat(ContratId pId, int pTypeAvenantId, int pQualificationId, int pStatutContratId, DateTime pDateAvenant, bool pTacheRisque, bool pIntemperie, bool pRisque, bool pSurveillanceMedical)
 -         {
 -             this.id = pId;
 -             this.typeavenantid = pTypeAvenantId;
 -             this.qualificationid = pQualificationId;
 -             this.statutcontratid = pStatutContratId;
 -             this.dateavenant = pDateAvenant;
 -             this.tacherisque = pTacheRisque;
 -             this.intemperie = pIntemperie;
 -             this.risque = pRisque;
 -             this.surveillancemedical = pSurveillanceMedical;
 -         }
 -         #endregion
 -         #region Public Properties
 -         public ContratId Id
 -         {
 -             get { return id; }
 -             set { _bIsChanged |= (id != value); id = value; }
 -         }
 -         public int TypeAvenantId
 -         {
 -             get { return typeavenantid; }
 -             set { _bIsChanged |= (typeavenantid != value); typeavenantid = value; }
 -         }
 -         public int QualificationId
 -         {
 -             get { return qualificationid; }
 -             set { _bIsChanged |= (qualificationid != value); qualificationid = value; }
 -         }
 -         public int StatutContratId
 -         {
 -             get { return statutcontratid; }
 -             set { _bIsChanged |= (statutcontratid != value); statutcontratid = value; }
 -         }
 -         public DateTime DateAvenant
 -         {
 -             get { return dateavenant; }
 -             set { _bIsChanged |= (dateavenant != value); dateavenant = value; }
 -         }
 -         public bool TacheRisque
 -         {
 -             get { return tacherisque; }
 -             set { _bIsChanged |= (tacherisque != value); tacherisque = value; }
 -         }
 -         public bool Intemperie
 -         {
 -             get { return intemperie; }
 -             set { _bIsChanged |= (intemperie != value); intemperie = value; }
 -         }
 -         public bool Risque
 -         {
 -             get { return risque; }
 -             set { _bIsChanged |= (risque != value); risque = value; }
 -         }
 -         public bool SurveillanceMedical
 -         {
 -             get { return surveillancemedical; }
 -             set { _bIsChanged |= (surveillancemedical != value); surveillancemedical = value; }
 -         }
 -         public bool IsDeleted
 -         {
 -             get
 -             {
 -                 return _bIsDeleted;
 -             }
 -             set
 -             {
 -                 _bIsDeleted = value;
 -             }
 -         }
 -         public bool IsChanged
 -         {
 -             get
 -             {
 -                 return _bIsChanged;
 -             }
 -             set
 -             {
 -                 _bIsChanged = value;
 -             }
 -         }
 -         #endregion
 -     }
 -     #region Custom ICollection interface for Contrat
 -     public interface IContratCollection : ICollection
 -     {
 -         Contrat this[int index] { get; set; }
 -         void Add(Contrat pContrat);
 -         void Clear();
 -     }
 -     [Serializable]
 -     public class ContratCollection : IContratCollection
 -     {
 -         private IList<Contrat> _arrayInternal;
 -         public ContratCollection()
 -         {
 -             _arrayInternal = new List<Contrat>();
 -         }
 -         public ContratCollection(IList<Contrat> pSource)
 -         {
 -             _arrayInternal = pSource;
 -             if (_arrayInternal == null)
 -             {
 -                 _arrayInternal = new List<Contrat>();
 -             }
 -         }
 -         public Contrat this[int index]
 -         {
 -             get
 -             {
 -                 return _arrayInternal[index];
 -             }
 -             set
 -             {
 -                 _arrayInternal[index] = value;
 -             }
 -         }
 -         public int Count { get { return _arrayInternal.Count; } }
 -         public bool IsSynchronized { get { return false; } }
 -         public object SyncRoot { get { return _arrayInternal; } }
 -         public void CopyTo(Array array, int index) { _arrayInternal.CopyTo((Contrat[])array, index); }
 -         public IEnumerator GetEnumerator() { return _arrayInternal.GetEnumerator(); }
 -         public void Add(Contrat pContrat) { _arrayInternal.Add(pContrat); }
 -         public void Clear() { _arrayInternal.Clear(); }
 -         public IList<Contrat> GetList() { return _arrayInternal; }
 -     }
 -     #endregion
 - }
 
  |  
 
   Lorsque que je compile via mon "Main" : j'obtient l'erreur suivante qui apparemment et normal :    
  
 L'application démarre...
   System.TypeInitializationException: Une exception a été levée par l'initialiseur
  de type pour 'adecco.NHibernateHelper'. ---> NHibernate.MappingException: Could
  not compile the mapping document: adecco.Mapping.Contrat.hbm.xml ---> NHibernat
 e.MappingException: composite-id class must override Equals(): adecco.Entities.C
 ontratId
    à NHibernate.Cfg.HbmBinder.BindRootClass(XmlNode node, RootClass model, Mappi
 ngs mappings)
    à NHibernate.Cfg.HbmBinder.BindRoot(XmlDocument doc, Mappings mappings)
    à NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
    --- Fin de la trace de la pile d'exception interne ---
    à NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
    à NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
    à NHibernate.Cfg.Configuration.ProcessMappingsQueue()
    à NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument docum
 ent)
    à NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String n
 ame)
    à NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String n
 ame)
    à NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
    à NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
    à NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
    à NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc)
    à NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
    à NHibernate.Cfg.Configuration.Configure(String fileName)
    à NHibernate.Cfg.Configuration.Configure()
    à adecco.NHibernateHelper..cctor() dans D:\Mes Documents\Visual Studio 2008\P
 rojects\adecco\adecco\NHibernateHelper.cs:ligne 22
    --- Fin de la trace de la pile d'exception interne ---
    à adecco.NHibernateHelper.GetCurrentSession()
    à adecco.Manager.TypeAvenantManager..ctor() dans D:\Mes Documents\Visual Stud
 io 2008\Projects\adecco\adecco\Manager\TypeAvenantManager.cs:ligne 20
    à adecco.Program.Main(String[] args) dans D:\Mes Documents\Visual Studio 2008
 \Projects\adecco\adecco\Program.cs:ligne 22
   L'application est fermée!
   |  
 
   La ligne que je retient est : composite-id class must override Equals(): adecco.Entities.C
 ontratId
 Cependant, je ne comprend pas où est ce que je dois implémenter la méthode Equals ?     Est ce que qu'elqu'un pourrait m'aider ?   SVP, c la galère ...
 Cordialement,
 Olive
     |