locked
Ideas for creating EF query RRS feed

  • Question

  • User-1335002297 posted

    How would the query look for getting all the related objects from this code first database?

    Say that I want to search from a Frys entity. Feel free to comment the Model.

    I want to query the database to get all of the Innehåll and BoxInfo which are a Many-to-Many relationship. Thanks!

    public class Innehåll
        {
            public Innehåll(int antal)
            {
                this.Antal = antal;
                this.Frysar = new HashSet<Frys>();
            }
            public Innehåll() { this.Frysar = new HashSet<Frys>(); }
            [Key]
            public int Id { get; set; }
            public int Antal { get; set; }
    
            //public virtual BoxInfo Box { get; set; }
            public virtual ICollection<Frys> Frysar { get; set; }
            public virtual ICollection<BoxInfo> BOX { get; set; }
    }
    
    public class Frys
        {
            public Frys(string ort)
            {
                this.Ort = ort;
                this.Innehåller = new HashSet<Innehåll>();
            }
    
            public Frys() { this.Innehåller = new HashSet<Innehåll>(); }
            [Key]
            public int Id { get; set; }
            public string Ort { get; set; }
            public int teslse { get; set; }
    
            public virtual ICollection<Innehåll> Innehåller { get; set; }
        }
    
    public class BoxInfo
        {
            public BoxInfo() { this.TillhörInnehåll = new HashSet<Innehåll>(); }
    
            public BoxInfo(string typ, decimal pris)
            {
                this.Typ = typ;
                this.Pris = pris;
            }
            public int Id { get; set; }
            public string Typ { get; set; }
            public decimal Pris { get; set; }
    
    
            public virtual ICollection<Innehåll> TillhörInnehåll { get; set; }
            
        }
    

    Friday, August 21, 2015 4:02 PM

Answers