Esempio n. 1
0
        private void ConfigInMemory()
        {
            Modelo modelo;

            modelo = new Modelo()
            {
                Id        = modelo1,
                Descricao = "FH"
            };
            _contextMemory.Modelos.Add(modelo);

            modelo = new Modelo()
            {
                Id        = modelo2,
                Descricao = "FM"
            };
            _contextMemory.Modelos.Add(modelo);

            modelo = new Modelo()
            {
                Id        = modelo3,
                Descricao = "FD"
            };
            _contextMemory.Modelos.Add(modelo);
            _contextMemory.SaveChanges();

            var entity3 = _contextMemory.Find <Modelo>(modelo1); //To Avoid tracking error

            _contextMemory.Entry(entity3).State = EntityState.Detached;
            var entity4 = _contextMemory.Find <Modelo>(modelo2); //To Avoid tracking error

            _contextMemory.Entry(entity4).State = EntityState.Detached;
            var entity5 = _contextMemory.Find <Modelo>(modelo3); //To Avoid tracking error

            _contextMemory.Entry(entity5).State = EntityState.Detached;
        }
Esempio n. 2
0
        private void ConfigInMemory()
        {
            Modelo modelo;

            modelo = new Modelo()
            {
                Id        = modelo1,
                Descricao = "FH"
            };
            _contextMemory.Modelos.Add(modelo);

            modelo = new Modelo()
            {
                Id        = modelo2,
                Descricao = "FM"
            };
            _contextMemory.Modelos.Add(modelo);

            modelo = new Modelo()
            {
                Id        = modelo3,
                Descricao = "FD"
            };
            _contextMemory.Modelos.Add(modelo);
            _contextMemory.SaveChanges();

            var modeloFH = _contextMemory.Modelos.FirstOrDefault(c => c.Descricao == "FH");

            Caminhao caminhao;


            caminhao = new Caminhao(caminhao1, DateTime.UtcNow.Year, DateTime.UtcNow.AddYears(1).Year, DateTime.UtcNow, modeloFH);

            _contextMemory.Caminhoes.Add(caminhao);

            var modeloFM = _contextMemory.Modelos.FirstOrDefault(c => c.Descricao == "FM");

            caminhao = new Caminhao(caminhao2, DateTime.UtcNow.Year, DateTime.UtcNow.Year, DateTime.UtcNow, modeloFM);



            _contextMemory.Caminhoes.Add(caminhao);
            _contextMemory.SaveChanges();


            var entity1 = _contextMemory.Find <Caminhao>(caminhao1); //To Avoid tracking error

            _contextMemory.Entry(entity1).State = EntityState.Detached;
            var entity2 = _contextMemory.Find <Caminhao>(caminhao2); //To Avoid tracking error

            _contextMemory.Entry(entity2).State = EntityState.Detached;

            var entity3 = _contextMemory.Find <Modelo>(modelo1); //To Avoid tracking error

            _contextMemory.Entry(entity3).State = EntityState.Detached;
            var entity4 = _contextMemory.Find <Modelo>(modelo2); //To Avoid tracking error

            _contextMemory.Entry(entity4).State = EntityState.Detached;
            var entity5 = _contextMemory.Find <Modelo>(modelo3); //To Avoid tracking error

            _contextMemory.Entry(entity5).State = EntityState.Detached;
        }