Error with Insert MSSQL, PetaPoco and C # (WPF)

0

Good morning, I am developing a desktop application using WPF, in visual Studio 2017 ; and I'm using the PetaPoco library for CRUD with SQL.

I would like to know if you could advise me in this case, since I do not find much information on the PetaPoco support page, and I can not understand exactly what the reason for the error is. Thanks in advance.

The error is as follows, and it appears when I try to insert a new record with the Insert method of PetaPoco.

"Object reference not set to an instance of an object."

Here the code:

Database db = new Database("Conexion");

 [TableName("PEDIMENTOIMP")]
    [PrimaryKey("idPedimento")]
    public class Prueba
    {
        [Column]
        public int NoPedimento { get; set; }
        [Column]
        public int YearFact { get; set; }
        [Column]
        public int ipTipo { get; set; }
        [Column]
        public int idClavePed { get; set; }
        [Column]
        public DateTime FechaInicial { get; set; }
        [Column]
        public DateTime FechaFinal { get; set; }
        [Column]
        public DateTime Fecha { get; set; }
        [Column]
        public double TipoCambio { get; set; }
        [Column]
        public string NoAgente { get; set; }
        [Column]
        public string ClaveAduana { get; set; }
        [Column]
        public string Semana { get; set; }
        [Column]
        public string AcuseRecibo { get; set; }
        [Column]
        public string AcuseReciboFact { get; set; }
        [Column]
        public int idPedimento { get; set; }
        [Column]
        public int Consolidado { get; set; }
    }

public void InserInto()
    {
        var pedimento = new Prueba
        {
            NoPedimento = 1253,
            YearFact = 2018,
            ipTipo = 1,
            idClavePed = 1,
            FechaInicial = DateTime.Now,
            FechaFinal = DateTime.Now,
            Fecha = DateTime.Now,
            TipoCambio = 1,
            ClaveAduana = "1",
            NoAgente = "1",
            Semana = "1",
            AcuseRecibo = "1",
            AcuseReciboFact = "1",
            Consolidado =1
        };

db.Insert("PEDIMENTOIMP", "idPedimento",false,  pedimento)

Specifically, I get an error in the code segment:

object id = _provider.ExecuteInsert(this, cmd, primaryKeyName);
                    // Assign the ID back to the primary key property
                    if (primaryKeyName != null && !poco.GetType().Name.Contains("AnonymousType"))
                    {
                        PocoColumn pc;
                        if (pd.Columns.TryGetValue(primaryKeyName, out pc))
                        {
                            pc.SetValue(poco, pc.ChangeType(id));
                        }
                    }

of the PetaPoco.cs file

    
asked by Angel Lara 30.03.2018 в 22:11
source

0 answers