c# - Why does DbContext instantiate repositories? -


in following code, dbcontext instantiates repositories in derived class. believe somehow reflection in constructor. these questions :

  1. why , purpose it?
  2. is instantiating properties in self or derived classes best practice?
  3. if best practice design pattern related , name of behavior?

this code in project, add entityframework reference console application project :

class program {     static void main(string[] args)     {         var context = new datacontext();         if(context.products != null)             console.writeline("why repositories not null?!");     } }  public class product { }  public class datacontext : dbcontext {     public idbset<product> products { get; set; } }  

dbcontext class internal entity framework assembly cannot modify within code. therefore, creating dbset properties in derived class, entity framework maps properties of type t database table columns. of internal entity framework magic happens within dbset class.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -