locked
My models for database if using entity framework 7 code first RRS feed

  • Question

  • I have three tables. Settings, Facilities and FacilitySettingOverride.

    Settings has the default values, Facilities has the list of facilities. And FacilitySettingOverride will override the default values in Settings.

    Here are the sample data.

    Settings table
    
    ID   Name     Value
    1    test1    true
    2    test2    true

    AND

    Facilities
    
    ID    Name
    163   Demo1
    164   Demo2

    then

    FacilitySettingOverride
    FacilityId      SettingId   Value
    163               2         False
    164               1         False
    164               2         False

    So FacilitySettingOverride has two foreign keys---FacilityId and SettingId

    In entity framework code first for existing database. I have the POCO classes as

     [Table("Settings")]
        public class Setting
        {
            [Key]
            public int Id { get; set; }
            public string Name { get; set; }
            public string Value { get; set; }
           
            public FacilitySettingOverride FacilitySettingOverride { get; set; }
        }

    And

    [Table("Facilities")]
        public class Facility
        {
            [Key]
            public int Id { get; set; }
            public string Name { get; set; }
            public  virtual ICollection<FacilitySettingOverride> FacilitySettingOverrides { get; set; }
        }
    And 
     [Table("FacilitySettingOverride")]
        public class FacilitySettingOverride
        {
            [Key]
            [ForeignKey("FacilityId")]
            public int FacilityId { get; set; }
    
            public string Value { get; set; }
            [ForeignKey("SettingId")]
            public int SettingId { get; set; }
    
            public virtual Facility Facility { get; set; }
            public virtual Setting Setting { get; set; }
    I am not sure if it is correct as I came across an error in somewhere. Also EF7 RC1 does not support automatic lazy loading and eager loading related objects in the same way that EF6 did. 

    Urgent: I have been debugging this for two days, thanks for help.


    • Moved by CoolDadTx Tuesday, May 24, 2016 1:48 PM EF related
    Monday, May 23, 2016 3:32 PM

Answers

  • Hello,

    Entity Framework 7/EFCore at this time does not support lazy loading at this time.

    https://github.com/aspnet/EntityFramework/wiki/Roadmap


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by HZ.USA Tuesday, May 24, 2016 6:33 PM
    Tuesday, May 24, 2016 2:42 AM

All replies