c# - Why does DbContext instantiate repositories? -
in following code, dbcontext instantiates repositories in derived class. believe somehow reflection in constructor. these questions :
- why , purpose it?
- is instantiating properties in self or derived classes best practice?
- 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
Post a Comment