FOREIGN KEY fetching

Feb 18, 2016 at 12:25 PM
Edited Feb 18, 2016 at 12:26 PM
Hi!
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):
    [Table("Repairs")]
    public partial class Repair
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }

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

        [StringLength(70)]
        public string SN { get; set; }

        public bool? Warranty { get; set; }

        [StringLength(255)]
        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.
    [Table("Users")]
    public partial class User
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ClientId { get; set; }

        [StringLength(60)]
        public string ClientType { get; set; }

        [StringLength(160)]
        public string ClientName { get; set; }

        [StringLength(180)]
        public string Address { get; set; }

        [StringLength(60)]
        public string Telephone { get; set; }

        [StringLength(60)]
        public string Mobile { get; set; }

        [StringLength(50)]
        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();