FOREIGN KEY fetching

Feb 18, 2016 at 12:25 PM
Edited Feb 18, 2016 at 12:26 PM
I have table with foreign keys to other tables created by code-first method of Entity Framework.
When someone edit/add row in table (for example, change first foreign key or add new row) your dll can't fetch data in foreign keys (NULL at cell with references)
Problem: need all data fields with foreign keys data INCLUD'ing
Can you help me?
Example (main table have foreign keys User, CurrentStatus, RepairStatus):
    public partial class Repair
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }

        [Column(TypeName = "date")]
        public DateTime Date { get; set; }

        public string SN { get; set; }

        public bool? Warranty { get; set; }

        public string Items { get; set; }

        public virtual User User { get; set; }

        public virtual RepairStatus RepairStatus { get; set; }

        public virtual CurrentStatus CurrentStatus { get; set; }
For example one help table with reference from main table.
    public partial class User
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ClientId { get; set; }

        public string ClientType { get; set; }

        public string ClientName { get; set; }

        public string Address { get; set; }

        public string Telephone { get; set; }

        public string Mobile { get; set; }

        public string EMail { get; set; }

        public virtual ICollection<Repair> Repairs { get; set; }
        public User()
            Repairs = new List<Repair>();
Feb 24, 2016 at 5:43 AM
Hi Siggraph

Sorry, but SqlTableDependency works only for scalar properties (int, short, bit, string, decimal and so on...).
So, properties as:
public virtual User User { get; set; }
are not "loaded". Only:
public int UserId { get; set; }
is filled with relative database value.

In order to load referenced entities, you have to do it manually:
context.Entry(epairEntity).Reference(l => l.User).Load();