Mapping 实体框架5的列名无效?

Mapping 实体框架5的列名无效?,mapping,entity-framework-5,fluent,Mapping,Entity Framework 5,Fluent,我尝试测试WPF、C#和EF5以开发桌面应用程序。 执行context.SaveChanges时,出现以下异常: 列名称simulation\u SimulationID无效。我尝试了几个技巧,但我无法解决这个问题,一切似乎都是正确的。以下实体: //Entity Echeance public partial class Echeance : INotifyPropertyChanged { public long EheanceId { get; set; } public

我尝试测试WPF、C#和EF5以开发桌面应用程序。 执行context.SaveChanges时,出现以下异常: 列名称simulation\u SimulationID无效。我尝试了几个技巧,但我无法解决这个问题,一切似乎都是正确的。以下实体:

//Entity Echeance
 public partial class Echeance : INotifyPropertyChanged
{
    public long EheanceId { get; set; }
    public byte EchNumber { get; set; }
    public System.DateTime date { get; set; }
    public Double principal { get; set; }
    public Double interet { get; set; }
    public byte isLoy1 { get; set; }
    public long SimulationId { get; set; }
    public virtual simulation simulation { get; set; }

    //Attributs non mappés
    public Double tva { get; set; }
    public Double txtva { get; set; }
    public Double horstaxe { get; set; }
    public Double ttc { get; set; }
    public Double amtfin { get; set; }
    public Double encfin { get; set; }

    //Constructeur avec numéro de loyer
    public Echeance(byte nnloy)
    {
        EchNumber = nnloy;
        date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 25);
        principal = 0.000;
        interet = 0.000;
        horstaxe = 0.000;
        tva = 0.000;
        ttc = 0.000;
        isLoy1 = 0;
        ttc = 0.000;
        amtfin = 0.000;
        encfin = 0.000;
    }



    //Constructeur sans paramètres avec valeurs par défaut
    public Echeance()
    {
        EchNumber = 0;
        date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 25);
        principal = 0.000;
        interet = 0.000;
        horstaxe = 0.000;
        tva = 0.000;
        ttc = 0.000;
        isLoy1 = 0;
        ttc = 0.000;
        amtfin = 0.000;
        encfin = 0.000;
    }



    //Propriété Numloy : numéro loyer
    public byte NumLoy
    {
        get { return EchNumber; }
        set
        {
            EchNumber = value;
            OnPropertyChanged("Numloy");
        }
    }

    public DateTime DateEcheance
    {
        get { return date; }
        set
        {
            date = value;
            OnPropertyChanged("DateEcheance");
        }

    }

    public Double MontantPrincipal
    {
        get
        {
            return principal;
        }

        set
        {
            principal = value;
            OnPropertyChanged("MontantPrincipal");
        }
    }


    public Double MontantInteret
    {
        get
        {
            return interet;
        }

        set
        {
            interet = value;
             OnPropertyChanged("MontantInteret");
        }
    }

    public Double MontantHT
    {
        get
        {
            return horstaxe;
        }

        set
        {
            horstaxe = value;
            OnPropertyChanged("MontantHT");
        }
    }


    public Double MontantTVA
    {
        get
        {
            return tva;
        }

        set
        {
            tva = value;
             OnPropertyChanged("MontantTVA");
        }
    }

    public Double MontantTTC
    {
        get
        {
            return ttc;
        }

        set
        {
            ttc = value;
             OnPropertyChanged("MontantTTC");
        }
    }


    public byte FirstLoyer
    {
        get { return isLoy1; }
        set
        {
            isLoy1 = value;
            OnPropertyChanged("FirstLoyer");
        }
    }

    public Double Encours
    {
        get { return encfin; }
        set
        {
            encfin = value;
            OnPropertyChanged("Encours");
        }
    }


    public Double Amortfin
    {
        get { return amtfin; }
        set
        {
            amtfin = value;
            OnPropertyChanged("Amortfin");
        }
    }


    public Double TauxTVA
    {
        get { return txtva; }
        set
        {
            txtva = value;
            OnPropertyChanged("TauxTVA");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

      protected void OnPropertyChanged(string name)
      {
          PropertyChangedEventHandler handler = PropertyChanged;

          if (handler != null)
              handler(this, new PropertyChangedEventArgs(name));

      }

}



//Entity simulation
 public partial class simulation : INotifyPropertyChanged
{

        public long SimulationId { get; set; }
        public Double baseLocative { get; set; }
        public Double txInt { get; set; }
        public Double txVr { get; set; }
        public Double Autofin { get; set; }
        public byte echjour { get; set; }
        public Byte duree { get; set; }
        public System.DateTime echBegin { get; set; }
        public Double loy1 { get; set; }
        public Byte loy1_freq { get; set; }
        public Double encfin { get; set; }
        public Double loyer { get; set; }
        public Double txtva { get; set; }
        public Byte perio { get; set; }
        public Double ratio { get; set; }

        public virtual IList<Echeance> echeancier { get; set; }
        //public virtual ICollection<Echeance> echeancier { get; set; }

        //Non mappés 

        Double Totpri;
        Double Totint;
        Double Totht;
        Double Tottva;
        Double Totttc;
        Double loyDuplicate;
        Double _timbre;


      //Constructeur sans paramètres
        public simulation()
        {
            baseLocative = 0.000;
            txInt = 0.000;
            txVr = 0.000;
            Autofin = 0.000;
            echjour = 25;
            duree = 36;
            loyer = 0.000;
            loy1 = 0.000;
            loy1_freq =1;
            perio = 1;
            txtva = 18.000;
            Totpri = 0.000;
            Totint = 0.000;
            Totht = 0.000;
            Tottva = 0.000;
            Totttc = 0.000;
            loyDuplicate = 0.000;
            _timbre = 0.000;

            int y = DateTime.Today.Year;
            int m = DateTime.Today.Month;
            int djour = DateTime.Today.Day;
            int j = 25;

            if (djour > 25)
            {

                m = m + 1;
                    if (m > 12)
                    {
                        m = 1;
                        y = y + 1;
                    }
            }



            //Date française
            CultureInfo  culture = CultureInfo.CreateSpecificCulture("fr-FR");
            DateTimeStyles  styles = DateTimeStyles.None;
            DateTime dd;

            string datestring = j.ToString() + "/" + m.ToString() + "/" + y.ToString();
            DateTime.TryParse(datestring, culture, styles, out dd );
            echBegin = dd;

           echeancier = new List<Echeance>();
        }


        //Constructeur avec  paramètres
        public simulation(Double bl, Double txi, Double txr, Double autofin, Byte jouech, Byte ldur, DateTime ech1, Double loy1mnt, Byte per,Double timbre)
        {
            baseLocative = bl;
            txInt = txi;
            txVr = txr;
            perio = per;
            Autofin = autofin;
            echjour = jouech;
            duree = ldur;
            echBegin = ech1;
            loy1 = loy1mnt;
            loy1_freq = 1;
            encfin = 0.000;
            ratio = 0.000;
            _timbre = timbre;
            echeancier = new List<Echeance>();
        }


        //Propriété base locative
        public Double Montant
        {
            get { return baseLocative; }
            set
            {
                baseLocative = value;
                OnPropertyChanged("Montant");
            }

        }

        //Propriété Taux d'intérêts
        public Double Txtint
        {
            get { return txInt; }
            set
            {
                txInt = value;
                OnPropertyChanged("Txtint");
            }

        }


        //Propriété Taux valeur résiduelle
        public Double Txtvr
        {
            get { return txVr; }
            set
            {
                txVr = value;
                OnPropertyChanged("Txtvr");
            }

        }


        //Propriété Autofinancement
        public Double Autofinancement
        {
            get { return Autofin; }
            set
            {
                Autofin = value;
                OnPropertyChanged("Autofinancement");
            }

        }

        //Propriété Jour échéance
        public Byte JourEcheance
        {
            get { return echjour; }
            set
            {
                echjour = value;
                OnPropertyChanged("JourEcheance");
            }

        }

        //Propriété Jour échéance
        public Byte DureeCtr
        {
            get { return duree; }
            set
            {
                duree = value;
                OnPropertyChanged("DureeCtr");
            }

        }

        //Propriété Jour échéance
        public DateTime BeginEch
        {
            get { return echBegin; }
            set
            {
                echBegin = value;
                OnPropertyChanged("BeginEch");
            }

        }

        //Propriété Jour échéance
        public Double Loyer
        {
            get { return loyer; }
            set
            {
                loyer = value;
                OnPropertyChanged("Loyer");
            }
        }

        //Périodicté
        public Byte Periodicite
        {
            get { return perio; }
            set
            {
                perio = value;
                OnPropertyChanged("Periodicite");
            }
        }



        //Premier loyer
        public Double FirstLoyer
        {
            get { return loy1; }
            set
            {
                loy1 = value;
                OnPropertyChanged("FirstLoyer");
            }
        }

        public Double TxtTva
        {
            get { return txtva; }
            set
            {
                txtva = value;
                OnPropertyChanged("TxtTva");
            }
        }


        //Nombre de répétition du premier loyer
        public Byte FrequenceLoy1
        {
            get { return loy1_freq; }
            set
            {
                loy1_freq = value;
                OnPropertyChanged("FrequenceLoy1");
            }
        }


        public Double TotalPri
        {
            get { return Totpri ; }
            set
            {
                Totpri = value;
                OnPropertyChanged("TotalPri");
            }
        }

        public Double TotalInt
        {
            get { return Totint; }
            set
            {
                Totint = value;
                OnPropertyChanged("TotalInt");
            }
        }

        public Double TotalHt
        {
            get { return Totht; }
            set
            {
                Totht = value;
               OnPropertyChanged("TotalHt");
            }
        }



        public Double TotalTva
        {
            get { return Tottva; }
            set
            {
                Tottva = value;
             OnPropertyChanged("TotalTva");
            }
        }

        public Double TotalTtc
        {
            get { return Totttc; }
            set
            {
                Totttc = value;
                OnPropertyChanged("TotalTtc");
            }
        }


        public Double Encfin
        {
            get { return encfin; }
            set
            {
                encfin = value;
                OnPropertyChanged("Encfin");
            }
        }

        public Double Ratio
        {
            get { return ratio; }
            set
            {
                ratio = value;
                OnPropertyChanged("Ratio");
            }
        }


        public Double LoyForDuplicate
        {
            get
            {
                return loyDuplicate;
            }
            set
            {
                loyDuplicate = value;
                OnPropertyChanged("LoyForDuplicate");
            }
        }


        //public IList<Echeance> ListEcheances
        public IList<Echeance> ListEcheances
        {
            get
            {
                return echeancier;
            }
            set
            {
                echeancier = value;
                OnPropertyChanged("ListEcheance");
            }
        }


        public Double Timbre
        {
            get
            {
                return _timbre;
            }
            set
            {
                _timbre = value;
                OnPropertyChanged("Timbre");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
}
//实体e含义
公共部分类E含义:INotifyPropertyChanged
{
公共长EheanceId{get;set;}
公共字节编号{get;set;}
public System.DateTime日期{get;set;}
公共双主体{get;set;}
公共双interet{get;set;}
公共字节isLoy1{get;set;}
公共长模拟ID{get;set;}
公共虚拟仿真{get;set;}
//非映射属性
公共双tva{get;set;}
公共双txtva{get;set;}
公共双horstaxe{get;set;}
公共双ttc{get;set;}
公共双amtfin{get;set;}
公共双加密{get;set;}
//建筑工人
公共电子含义(字节nnloy)
{
EchNumber=nnloy;
日期=新的日期时间(DateTime.Today.Year,DateTime.Today.Month,25);
本金=0.000;
interet=0.000;
horstaxe=0.000;
tva=0.000;
ttc=0.000;
isLoy1=0;
ttc=0.000;
amtfin=0.000;
encfin=0.000;
}
//StudioTr.PARAME-TRAS AVEC ValueS PARD Deffut
公共意义()
{
编号=0;
日期=新的日期时间(DateTime.Today.Year,DateTime.Today.Month,25);
本金=0.000;
interet=0.000;
horstaxe=0.000;
tva=0.000;
ttc=0.000;
isLoy1=0;
ttc=0.000;
amtfin=0.000;
encfin=0.000;
}
//专有名词:numéro loyer
公共字节数
{
获取{return EchNumber;}
设置
{
EchNumber=值;
不动产变更(“Numloy”);
}
}
公共日期时间日期含义
{
获取{返回日期;}
设置
{
日期=价值;
不动产变更(“日期含义”);
}
}
公共双蒙塔特原则
{
得到
{
返还本金;
}
设置
{
本金=价值;
不动产变更(“MontantPrincipal”);
}
}
公共双月台
{
得到
{
返回因特网;
}
设置
{
interet=值;
物业变更(“MontantInteret”);
}
}
公共双蒙坦特酒店
{
得到
{
返回地垒;
}
设置
{
horstaxe=值;
不动产变更(“蒙坦特”);
}
}
公共双蒙塔特瓦酒店
{
得到
{
返回tva;
}
设置
{
tva=值;
不动产变更(“MontantTVA”);
}
}
公共双蒙塔
{
得到
{
返回ttc;
}
设置
{
ttc=数值;
OnProperty变更(“Montanttc”);
}
}
公共字节第一层
{
获取{return isLoy1;}
设置
{
isLoy1=值;
OnProperty变更(“FirstLoyer”);
}
}
公众双重鼓励
{
获取{return encfin;}
设置
{
encfin=数值;
OnPropertyChanged(“Encours”);
}
}
公共双阿莫特芬
{
获取{return amtfin;}
设置
{
amtfin=值;
不动产变更(“Amortfin”);
}
}
公共双TauxTVA
{
获取{return txtva;}
设置
{
txtva=值;
OnPropertyChanged(“TauxTVA”);
}
}
公共事件属性更改事件处理程序属性更改;
受保护的void OnPropertyChanged(字符串名称)
{
PropertyChangedEventHandler处理程序=PropertyChanged;
if(处理程序!=null)
处理程序(此,新PropertyChangedEventArgs(名称));
}
}
//实体模拟
公共部分类模拟:INotifyPropertyChanged
{
公共长模拟ID{get;set;}
公共双baseLocative{get;set;}
公共双txInt{get;set;}
公共双txVr{get;set;}
公共双自动fin{get;set;}
公共字节echjour{get;set;}
公共字节duree{get;set;}
public System.DateTime{get;set;}
公共双loy1{get;set;}
公共字节loy1_freq{get;set;}
公共双加密{get;set;}
公共双loyer{get;set;}
公共双txtva{get;set;}
公共字节周期{get;set;}
公共双重比率{get;set;}
公共虚拟IList echeancier{get;set;}
//公共虚拟ICollection echeancier{get;set;}
//非映射
双Totpri;
双积分;
双托特;
双Tottva;
双tottc;
双倍的;
双重音色;
//无参数施工人员
公共模拟()
{
baseLocative=0.000;
txInt=0.000;
txVr=0.000;
Autofin=0.000;
echjour=25;
duree=36;
loyer=0.000;
loy1=0.000;
loy1_freq=1;
perio=1;
txtva=18.000;
Totpri=0.000;
总积分=0.000;
Totht=0.000;
Tottva=0.000;
TOTTC=0.000;
倍数=0.000;
_音色=0.000;
int y=DateTime.Today.Year;
int m=DateTime.Today.Month;
int djour=DateTime.Today.Day;
int j
 public class MyContext : DbContext
{

    ILogger _currentLog = null;

    public DbSet<simulation> Simulations { get; set; }
    public DbSet<Echeance> Echeances { get; set; }


    public MyContext(string cnxString, ILogger logger)
        : base(cnxString)
    {
        Database.SetInitializer<MyContext>(null);
        _currentLog = logger;
        if (_currentLog != null)
            _currentLog.LogInfoMessage("Connexion établie.");
    }

    public MyContext(ILogger logger)
        : base("name=dbleaseEntities")
    {
      //  Database.SetInitializer<MyContext>(null);
        _currentLog = logger;
        if (_currentLog != null)
             _currentLog.LogInfoMessage("Connexion établie.");
    }


    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        _currentLog.LogInfoMessage("Mapping en cours...");
        try
        {
            modelBuilder.Configurations.Add(new SimulationMapping());
            modelBuilder.Configurations.Add(new EcheanceMapping());

            //************************************************************************************************************************
            //Propriétés non mappées (à ignorer) pour l'entité simulation 
            //Autofinancement JourEcheance DureeCtr BeginEch Loyer Periodicite FirstLoyer TxtTva FrequenceLoy1 LoyForDuplicate Timbre
            //Les propriétés à ignorer lors de mapping
            //************************************************************************************************************************
            _currentLog.LogInfoMessage("Ignorer les champs de l'entité simulation.");
            modelBuilder.Entity<simulation>().Ignore(t => t.TotalPri);
            modelBuilder.Entity<simulation>().Ignore(t => t.TotalInt);
            modelBuilder.Entity<simulation>().Ignore(t => t.TotalHt);
            modelBuilder.Entity<simulation>().Ignore(t => t.TotalTva);
            modelBuilder.Entity<simulation>().Ignore(t => t.TotalTtc);
            modelBuilder.Entity<simulation>().Ignore(t => t.Montant);
            modelBuilder.Entity<simulation>().Ignore(t => t.Txtint);
            modelBuilder.Entity<simulation>().Ignore(t => t.Txtvr);
            modelBuilder.Entity<simulation>().Ignore(t => t.Autofinancement);
            modelBuilder.Entity<simulation>().Ignore(t => t.JourEcheance);
            modelBuilder.Entity<simulation>().Ignore(t => t.DureeCtr);
            modelBuilder.Entity<simulation>().Ignore(t => t.BeginEch);
            modelBuilder.Entity<simulation>().Ignore(t => t.Loyer);
            modelBuilder.Entity<simulation>().Ignore(t => t.Periodicite);
            modelBuilder.Entity<simulation>().Ignore(t => t.FirstLoyer);
            modelBuilder.Entity<simulation>().Ignore(t => t.TxtTva);
            modelBuilder.Entity<simulation>().Ignore(t => t.FrequenceLoy1);
            modelBuilder.Entity<simulation>().Ignore(t => t.LoyForDuplicate);
            modelBuilder.Entity<simulation>().Ignore(t => t.Ratio);
            modelBuilder.Entity<simulation>().Ignore(t => t.Timbre);
            modelBuilder.Entity<simulation>().Ignore(t => t.Encfin);

            //************************************************************************************************************************
            //Propriétés non mappées (à ignorer) pour l'entité Echeance 
            //NumLoy, DateEcheance, MontantPrincipal, MontantInteret, MontantHT, MontantTVA, MontantTTC, FirstLoyer, Encours, Amortfin, TauxTVA
            //tva, txtva,horstaxe, ttc, amtfin, encfin 
            //************************************************************************************************************************
            _currentLog.LogInfoMessage("Ignorer les champs de l'entité Echéance.");
            modelBuilder.Entity<Echeance>().Ignore(t => t.NumLoy);
            modelBuilder.Entity<Echeance>().Ignore(t => t.DateEcheance);
            modelBuilder.Entity<Echeance>().Ignore(t => t.MontantPrincipal);
            modelBuilder.Entity<Echeance>().Ignore(t => t.MontantInteret);
            modelBuilder.Entity<Echeance>().Ignore(t => t.MontantHT);
            modelBuilder.Entity<Echeance>().Ignore(t => t.MontantTVA);
            modelBuilder.Entity<Echeance>().Ignore(t => t.MontantTTC);
            modelBuilder.Entity<Echeance>().Ignore(t => t.FirstLoyer);
            modelBuilder.Entity<Echeance>().Ignore(t => t.Encours);
            modelBuilder.Entity<Echeance>().Ignore(t => t.Amortfin);
            modelBuilder.Entity<Echeance>().Ignore(t => t.TauxTVA);
            modelBuilder.Entity<Echeance>().Ignore(t => t.tva);
            modelBuilder.Entity<Echeance>().Ignore(t => t.txtva);
            modelBuilder.Entity<Echeance>().Ignore(t => t.horstaxe);
            modelBuilder.Entity<Echeance>().Ignore(t => t.ttc);
            modelBuilder.Entity<Echeance>().Ignore(t => t.amtfin);
            modelBuilder.Entity<Echeance>().Ignore(t => t.encfin);

            base.OnModelCreating(modelBuilder);
            _currentLog.LogInfoMessage("Mapping terminée avec succès.");
        }
        catch (Exception ex)
        {
            _currentLog.LogException(ex);
            throw ex;

        }

    }
public class EcheanceMapping : EntityTypeConfiguration<Echeance>
{
    public EcheanceMapping()
    {
        this.HasKey(t => t.EheanceId);
        this.ToTable("Echeance");
        this.Property(t => t.EheanceId).HasColumnName("EheanceId").IsRequired()
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        this.Property(t => t.EchNumber).HasColumnName("EchNumber").IsRequired();
        this.Property(t => t.date).HasColumnName("date").IsRequired();
        this.Property(t => t.principal).HasColumnName("principal");
        this.Property(t => t.interet).HasColumnName("interet");
        this.Property(t => t.isLoy1).HasColumnName("isloy1").IsRequired();
        this.Property(t => t.SimulationId).HasColumnName("simulationId").IsRequired();
        this.HasRequired(t => t.simulation).WithMany(t => t.echeancier).HasForeignKey(d => new { d.SimulationId });



    }
}

 public class SimulationMapping : EntityTypeConfiguration<simulation>
{
 public SimulationMapping()
    {
        this.HasKey(t => t.SimulationId);
        this.ToTable("simulation");
        this.Property(t => t.SimulationId)
            .HasColumnName("SimulationId")
            .IsRequired()
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            //.HasDatabaseGeneratedOption(new Nullable<DatabaseGeneratedOption>(DatabaseGeneratedOption.Identity));

        this.Property(t => t.baseLocative).HasColumnName("Baselocative").IsRequired();
        this.Property(t => t.txInt).HasColumnName("txInt").IsRequired();

           this.Property(t => t.txVr).HasColumnName("txvr");
           this.Property(t => t.Autofin).HasColumnName("Autofin");
           this.Property(t => t.echjour).HasColumnName("echjour").IsRequired();
           this.Property(t => t.duree).HasColumnName("duree").IsRequired();
           this.Property(t => t.echBegin).HasColumnName("echBegin").IsRequired();
           this.Property(t => t.loy1).HasColumnName("loy1");
           this.Property(t => t.loy1_freq).HasColumnName("loy1_freq");
           this.Property(t => t.encfin).HasColumnName("encfin");
           this.Property(t => t.loyer).HasColumnName("loyer");
           this.Property(t => t.txtva).HasColumnName("txtva");
           this.Property(t => t.perio).HasColumnName("perio").IsRequired();
           this.Property(t => t.ratio).HasColumnName("ratio");
    }
}
 public class UnitOfWork : MyContext, IUnitOfWork, IQueryableUnitOfWork
{

    private ILogger _logger;
    public UnitOfWork(string cnxString, ILogger logger) : base(cnxString, logger)
    {

    }

    public UnitOfWork(ILogger logger)
        : base(logger)
    {
        _logger = logger;
    }


    //Marquer une entitié de type <T> comme nouveau dans le contexte
    public void RegisterNew<T>(T item) where T : class
    {
        _logger.LogInfoMessage("Marquage d'une entitié [" + item.GetType().Name + "] comme nouveau.");
        try
        {
            if (item != null)
            {
                base.Entry<T>(item).State = EntityState.Added;
                _logger.LogInfoMessage("Marquage d'une entitié [" + item.GetType().Name + "] comme nouveau.");
            }
            else
                _logger.LogInfoMessage("Entité nulle lors de marquage comme nouveau.");
        }
        catch (Exception ex)
        {
            _logger.LogException(ex);
            throw ex;
        }

    }


    //Marquer une entitié de type <T> comme modifiée dans le contexte
    public void RegisterChanged<T>(T item) where T : class
    {

        base.Entry<T>(item).State = EntityState.Modified;

    }


    //Marquer une entitié de type <T> comme unchangé dans le contexte
    public void RegisterUnChanged<T>(T item) where T : class
    {
        base.Entry<T>(item).State = EntityState.Unchanged;

    }


    //Marquer une entitié de type <T> comme supprimée dans le contexte
    public void RegisterDeleted<T>(T item) where T : class
    {
        base.Entry<T>(item).State = EntityState.Deleted;

    }


    //Récupère du contexte le dbset du type <T>
    public IDbSet<T> GetSet<T>() where T : class
    {

        return base.Set<T>();
    }



    public IQueryable<T> GetQueryableSet<T>() where T : class
    {
         return base.Set<T>();

    }



    public void Rollback()
    {
        base.ChangeTracker.Entries().ToList().ForEach(e => e.State = EntityState.Unchanged);
    }



    public void Commit()
    {
        try
        {
            base.SaveChanges();
        }

        catch (DbUpdateException e)
        {
            var innerEx = e.InnerException;
            while (innerEx.InnerException != null)
                innerEx = innerEx.InnerException;
            throw new Exception(innerEx.Message);
        }

        catch (DbEntityValidationException e)
        {
            var sb = new StringBuilder();

            foreach (var entry in e.EntityValidationErrors)
            {
                foreach (var error in entry.ValidationErrors)
                {
                    sb.AppendLine(string.Format("{0}-{1}-{2}",
                    entry.Entry.Entity,
                    error.PropertyName,
                    error.ErrorMessage
                ));
                }
            }
            throw new Exception(sb.ToString());
        }
    }


    public void Attach<T>(T item) where T : class
    {
        base.Entry<T>(item).State = EntityState.Unchanged;
    }
}