0 votes
in Education by (1.7m points)
Department and store model. They are a one to one relationship. when I do the (Include) only some models it brings me the complete data. The data is correctly in the database

 var orders = await _context.Order.Include(o => o.Departament)

                                  .Include(o => o.Store).ToArrayAsync();

Model Order

 public class Order

    {   [Key]

        public string Order_Id { get; set; }

        [DataType(DataType.Date)]

        public DateTime Date { get; set; }

        public string Number_Order { get; set; }  

        

        public int Qty { get; set; }

        [DataType(DataType.DateTime)]

        public DateTime Imported { get; set; }

        [DataType(DataType.DateTime)]

        public DateTime Modified { get; set; }

        [DataType(DataType.DateTime)]

        public DateTime Exported { get; set; }

        public bool IsActive { get; set; }

        [ForeignKey("Departament")]

        public string DepartmentId { get; set; }

        

        [ForeignKey("Store")]

        public string StoreId { get; set; }

        public virtual ICollection<OrderDetail> OrderDetails { get; set; }

       

        public Departament Departament { get; set; }

        public Store  Store { get; set; }

    }

.

I just need to solve that problem of getting the data correctly.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
what do u mean one to one!!! i think your design is one to many. as Steve Py said in his comment ## The relationship between Order->Department and Order->Store is not One-to-One, it is Many-to-One. (Many orders could refer to the same Department) ##

use virtual keyword for navigation properties. accroding to https://stackoverflow.com/a/41881299/18399373 you can use virtual keyword to load related data in lazy way

use explicit loading and check it. Entity Framework supports three ways to load related data - eager loading, lazy loading and explicit loading
...