Entity Framework Code First setting does not generate foreign keys in the database

Source: Internet
Author: User

What version of EF are you using now? I use EF6, you can rewrite the sqlservermigrationsqlgenerator to generate foreign keys and update the foreign key method, the unnecessary tables are filtered out not OK?

1  Public classExtendedsqlgenerator:sqlservermigrationsqlgenerator2 {3         #regionFOREIGN key4         protected Override voidGenerate (dropforeignkeyoperation dropforeignkeyoperation)5         {6             if(Isignoretable (dropforeignkeyoperation.dependenttable))7                 return;8             Base. Generate (dropforeignkeyoperation);9         }Ten  One         protected Override voidGenerate (addforeignkeyoperation addforeignkeyoperation) A         { -             if(Isignoretable (addforeignkeyoperation.dependenttable)) -                 return; the             Base. Generate (addforeignkeyoperation); -         }  -         #endregion -  +  -}

Reference Path: http://q.cnblogs.com/q/65485/

Entity Framework Code First setting does not generate foreign keys in the database

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.