-1

I'm trying to make a CRUD but my variable NovaGarantia doesn't work and the error appears. Now I'm trying to do the INSERT. Follow bellow my code:

using EDP.GestaoVarejista.MOD;

namespace EDP.GestaoVarejista.DAL.CadastrosGerais;


    public class Garantias : Base
    {
        public int Inserir(Garantia garantia)
        {
            try
            {
                using (EDPGestaoVarejistaEntities dbEntities = new EDPGestaoVarejistaEntities())

                    tb_garantias NovaGarantia = new tb_garantias
                    {
                        descrGarantia = garantia.descGarantia   
                    };
            }
        }
}
RBT
  • 24,161
  • 21
  • 159
  • 240
Leo
  • 23
  • 1
  • 4
  • What's the error? – Dido Nov 06 '17 at 16:41
  • Is `tb_garantias` a class name? – Dido Nov 06 '17 at 16:41
  • Yes, public partial class tb_garantias – Leo Nov 06 '17 at 16:48
  • @Leonardo Ines what's the error message you're receiving? Is it a compile-time error or a run-time error? – Dido Nov 06 '17 at 16:50
  • When i'm typing and try to make this attribution ( tb_garantias NovaGarantia = new tb_garantias). They are underlined and the follow message appears when my mouse is over(Embedded statement cannot be a declaration or labeled statement). – Leo Nov 06 '17 at 16:58

1 Answers1

3

Try the following:

using EDP.GestaoVarejista.MOD;

namespace EDP.GestaoVarejista.DAL.CadastrosGerais;


    public class Garantias : Base
    {
        public int Inserir(Garantia garantia)
        {
            try
            {
                using (EDPGestaoVarejistaEntities dbEntities = new EDPGestaoVarejistaEntities())
                    {
                       tb_garantias NovaGarantia = new tb_garantias
                       {
                           descrGarantia = garantia.descGarantia   
                       };
                    }
            }
        }
}

The problem is that you do not delimit a scope for the using. This question goes into more details.

Dido
  • 520
  • 2
  • 7
  • 21