且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DbContext如何初始化自动DbSet< T>。属性?

更新时间:2022-03-13 15:02:41

通过查看反射的代码,在构造DbContext(基类)时,它会调用DbSetDiscoveryService(内部clasS)-本质上,它使用反射来查找DbContext上的所有属性。

From looking at the reflected code, when the DbContext (the base class) is constructed it makes a call to the DbSetDiscoveryService (an internal clasS) - which essentially uses reflection to find all properties on the DbContext, and then initializes those that need initializing.

简而言之-在构造函数中使用反射。

So in short - using reflection in the constructor.