I can’t get into the comic book with Entity

Asked

Viewed 62 times

1

This is my input code. Why is it wrong? What should I do?

public int abreOsParceiro(string os, string cnpj, string dataAbertura, string dataVisita, string tecnico)
        {
             WEBEntities db = new WEBEntities();
            PDVOsParceiro pdv = new PDVOsParceiro();
            List<string> lista = new List<string>();

            try
            {
                pdv.CNPJ = cnpj;
                pdv.DataAberturaOs = Convert.ToDateTime(dataAbertura);
                pdv.DataVisita = Convert.ToDateTime(dataVisita);
                pdv.Tecnico = tecnico;
                pdv.OS = Convert.ToInt32(os);

                db.T_OsParceiro.Add(pdv);==>> Aqui dá o erro
                db.SaveChanges();
            }

That is the mistake:

The best overloaded method match for 'System.Data.Entity.DbSet<V99SuporteTecnico.Models.T_OsParceiro>.Add(V99SuporteTecnico.Models.T_OsParceiro)' has some invalid arguments

What are the invalid arguments?

My class is so:

[Table(Name = "T_TarefaParceiro")]
    public class PDVOsParceiro
    {
        [Column]
        [DataMember]
        public int IDTarefaParceiro { get; set; }
        [Column]
        [DataMember]
        public int OS { get; set; }
        [Column]
        [DataMember]
        public DateTime DataAberturaOs { get; set; }
        [Column]
        [DataMember]
        public string CNPJ { get; set; }
...............

Is that right or not?

  • You would need to know your class declaring what the member is T_OsParceiro of db and check what the method Add is waiting. There is some method there that awaits a type PDVOsParceiro? If it does not exist, either you need to create or see if you can pass an element of another type or still see if it is possible to do cast for the expected type, which seems unlikely to me.

1 answer

2


The message says it all.

The context expects a T_OsParceiro. You’re passing a PDVOsParceiro. The right thing would be:

    public int abreOsParceiro(string os, string cnpj, string dataAbertura, string dataVisita, string tecnico)
    {
         WEBEntities db = new WEBEntities();
        T_OsParceiropdv = new T_OsParceiro();
        List<string> lista = new List<string>();

        try
        {
            /* Aqui não sei se o tipo T_OsParceiro tem os mesmos campos de PDVOsParceiro, mas a ideia é que ele seja preenchido neste ponto */

            db.T_OsParceiro.Add(pdv);
            db.SaveChanges();
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.