S
S
Sergey Konovalov2015-09-15 15:42:54
Oracle
Sergey Konovalov, 2015-09-15 15:42:54

Where is the error in the description of entities?

There are two tables, purchases and addresses. The purchase table stores the id of the address, and the addresses contain more detailed information about the address, respectively. Described each class:

[Table("ADRESSES")]
    public class Adresses
    {
        [Key]
        [Column("INDEXADRESS")]
        public int ID { get; set; }
        [Column("NAIMENOVANIE")]
        public string NameAdress { get; set; }
        public List<Zakupki> Zakupki { get; set; }
    }
    [Table("ZAKUPKI")]
    public class Zakupki
    {

        [Key]
        [Column("INDEXZAKUPKI")]
        public int IndexZakupki { get; set; }

        [Column("DATEZAKUPKI")]
        public DateTime Date { get; set; }

        [Column("OTKUDA")]
        public int Otkuda { get; set; }

        [Column("KOLICHESTVO")]
        public int Kolichestvo { get; set; }

        [Column("SUMMA")]
        public float Summa { get; set; }

        [Column("PARTIYA")]
        public int PartiyaID { get; set; }

        [ForeignKey("PartiyaID")]
        public Partiya Partiya { get; set; }

        [ForeignKey("Otkuda")]
        public Adresses Adresses { get; set; }
    }

and in the view, in foreach I want to display not the id of the address, but its name, hence dbContext.Zakupki.Adressesthe problem is that for some reason Adresses is null, like Partiya, and all other data is taken correctly. So the question is, either you can’t do it at all, or did I describe something incorrectly, or didn’t finish it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Litvinyuk, 2015-09-15
@zakar1ya

You need to do Fetch for addresses in purchases, or configure the mapping so that this link is not a lazy load. This behavior is a feature of the Entity Framework and is configurable. Read the documentation .

T
Tsiren Naimanov, 2015-09-15
@ImmortalCAT

I just tested lazy eagerly and explicity
using the benchmark ( homemade with Stopwatch ) and all sorts of garbage collectors,
the fastest was eagerly, it is faster than explicity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question