How do I allow entity in the entity Framework Db frist mode to inherit relationships?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.