using CD67.FicheCollege.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; namespace CD67.FicheCollege.Factory { public partial class AnneeFactory : Internal.BaseFactory { public AnneeFactory(Entities dbContext) : base(dbContext) { } public Annee getByLibelle(params object[] keyValues) { string libelle = keyValues[0].ToString(); Annee annee = base.getAll().Where(a=>a.Libelle == libelle).First(); //si l'élément n'existe pas, on le créé if (annee == null) { annee = new Annee() { Libelle = libelle }; this.add(ref annee); dbContext.Entry(annee).Reference(i => i.Colleges).Load(); } return annee; } } }