I can’t do include

Asked

Viewed 82 times

0

I try to make include, but the message appears :

inserir a descrição da imagem aqui In some of the research I’ve done they say to include using System.Linq; using System.Data.Entity; but mine already contains these.

My classes are:

Photoapparatus:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MeuProjeto.Models
{
    public class FotoAparelho
    {
        [Key]
        public int FotoAparelhoID { get; set; }

        [DisplayName("URL")]
        [Required(ErrorMessage = "Insira o link da imagem")]
        public string URL { get; set; }

        [DisplayName("Descrição")]
        [Required(ErrorMessage = "Descrição da Link")]
        public string Descricao { get; set; }

        [ForeignKey("Aparelho")]
        public int AparelhoID { get; set; }
        public virtual Aparelho Aparelho { get; set; }//Um aparelho
    }
}

And the Apparatus:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace MeuProjeto.Models
{
    public class Aparelho
    {
        [Key]
        public int AparelhoID { get; set; }

        [DisplayName("Nome")]
        [Required(ErrorMessage = "Preencha Nome")]
        [StringLength(255, MinimumLength = 3, ErrorMessage = "O nome do aparelho deve ter de 3 a 255 caracteres")]
        public string Nome { get; set; }

        [DisplayName("Descrição")]
        [Required(ErrorMessage = "Preencha a descrição do curso")]
        public string Descricao { get; set; }

        //Relacionamentos
        public virtual ICollection<FotoAparelho> Fotos { get; set; }
    }
}

I need to do the following: var aparelhos = db.Aparelhos.Incluce(c => c.Fotos);

1 answer

3


In this case Voce can follow 2 lines:

var aparelhos = from ap in db.Aparelhos.Include("Fotos")
            select ap;

To do so you need the Data.Entity namespace..

using System.Data.Entity;

var aparelhos = from ap in db.Aparelhos.Include(c => c.Fotos)
            select ap;
  • For me decided just by putting the using System.Data.Entity;

Browser other questions tagged

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