Show a fk name on the grid

Asked

Viewed 35 times

-1

This is the select of my proc

select f.id
               ,f.nome
               ,f.dataNascimento
               ,f.cpf
               ,f.cidade
               ,c.nome
         from  
            funcionarios f inner join cidade c on f.cidade = c.id

and my model cidae is like this

public class Cidade
    {
        public Cidade()
        {
            Funcionarios = new List<Funcionario>();
        }
        [Key]
        public int id { get; set; }
        [Required]         
        public String nome { get; set; }
        public virtual ICollection<Funcionario> Funcionarios { get; set; }
    }

and the Funcionario model

public class Funcionario
    {
        [Key]
        public int id { get; set; }
        [Required]
        public String nome { get; set; }
        [Required]
        public DateTime dataNascimento { get; set; }
        [Required]
        public long cpf { get; set; }
        [Required]
        public int cidade { get; set; }
        [ForeignKey("cidade")]
        public virtual int Cidade { get; set; }
    }

When I consume the service that goes to the bank, I get this error

System.Invalidoperationexception: 'The Property 'city' cannot be configured as a navigation Property. The Property must be a Valid Entity type and the Property should have a non-abstract getter and Setter. For Collection properties the type must implement Icollection Where T is a Valid Entity type.'

1 answer

3

Change

public virtual int Cidade { get; set; }

for

public virtual Cidade Cidade { get; set; }
  • Linq, the City camp is coming null at Postman. How do I bring the name of the city? In the bank proc returns, but in the mapping of the entity I do not know how to do this.

  • Ah, there’s something else, right... Give a thrashing there, soon you find the mistake.

  • Not the name of FK, but returns me a Join from the bank and in this Join I get the name of the city, but I do not know how to get by mapping, be it in Postman or View

  • OK.

  • I already solved it. Return in Proc

Browser other questions tagged

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