.net - Is it possible to implement concept of lazy loading/ Eager loading on memory object like List (Not with DB objects) -


i asking question clear confusion .net/entity framework possible implement lazy loading/eager loading concepts on memory objects database object. know entity framework provides feature inbuilt database entities. can use same approach (with or without using entity framework) in memory object class objects/list etc.

for example:

    public class student     {         public student() { }         public student(int studentid, string name, address address, list<subject> subjects)         {             studentid = studentid;             name = name;             address = address;             subjects = subjects;         }          public int studentid { get; set; }         public string name { get; set; }         public address address { get; set; }         public list<subject> subjects { get; set; }     }     public class address     {         public string addresslineone { get; set; }         public string addresslinetwo { get; set; }         public string city { get; set; }         public string state { get; set; }     }     public class subject     {         public int subjectid { get; set; }         public string subjectname { get; set; }     } 

i created object of student class properties initialized:

   public actionresult index()     {         student std = new student(1, "stduent1", new address { addresslineone = "#118 d-road", city = "chd", state = "chd" },             new list<subject> {                 new subject{ subjectid=1, subjectname="history" },                 new subject{ subjectid=2, subjectname="english" }             });          return view();     } 

all properties initialized , filled there way can load subject list , address object on demand only.

one option can initiaize address , list of subject when need it. possible way ef implement lazy loading.

i have studied lazy< t > didn't clarify same.

please provide valuable feedback/suggestions. in advance.

i not quite sure why want lazy loading of in memory, can ienumerable if understood want achieve correctly:

public class student {     public ienumerable<subject> subjects     {                 {             (int = 0; < 5; i++)             {                 yield return new subject();              }                         }     }  } 

you don't need yield return, depends on how subjects. each time movenext called (e.g. inside foreach) code called , you'll able fetch whatever need.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -