1. Create an Entity Data Model using DB Frist mode
Db Frist Create an Entity Data model (creating an EDMX is not the point, you can do it randomly), here named Zerocodedb, the resulting documents;
Where the red box of the file (ZEROCODEDB.TT) is the entity's generated key code, that is, entity's T4 template file, this article is to move the knife to this file.
2, modify the Entity T4 template file Implementation inheritance
Create a new class library The parent class and interface code are as follows
namespace zerocode.demolib{ publicclass deomclass{} public Interface idemointerface<outwhere tkey:iequatable<tkey> Get; }}}
View Code
Open the Zerocodedb.tt file (T4 template code highlighting needs to install the T4 template Editor, tools--Extensions and updates--Online search "T4 editor"),
Find the class name of the entity related generated code as shown in the left figure (about line No. 314), corresponding to the generated user entity as in the right image.
The Entityclassopening () method generates the string "public partial class User"
Scenario One: All inherit a certain class
scenario hypothesis: The EF-generated inheritance relationship is not required and all entities are inherited ZeroCode.DemoLib.DemoClass
Completing the above scenario requires two steps:
(1) Add a reference to the class library zerocode.demolib in the ZEROCODEDB.TT code;
(2) Replace the _code. Stringbefore (":", _typemapper.gettypename (entity. BaseType)), save the Run T4 template.
How do I allow entity in the entity Framework Db frist mode to inherit relationships?