码迷,mamicode.com
首页 > 数据库 > 详细

Entity Framework code first设置不在数据库中生成外键

时间:2014-12-12 16:26:41      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   sp   for   on   数据   

你现在用的EF是什么版本?我用EF6,你可以重写SqlServerMigrationSqlGenerator的生成外键和更新外键的方法,把不需要的表都过滤掉不就ok了?

 1 public class ExtendedSqlGenerator : SqlServerMigrationSqlGenerator
 2 {
 3         #region 外键
 4         protected override void Generate(DropForeignKeyOperation dropForeignKeyOperation)
 5         {
 6             if (IsIgnoreTable(dropForeignKeyOperation.DependentTable))
 7                 return;
 8             base.Generate(dropForeignKeyOperation);
 9         }
10 
11         protected override void Generate(AddForeignKeyOperation addForeignKeyOperation)
12         {
13             if (IsIgnoreTable(addForeignKeyOperation.DependentTable))
14                 return;
15             base.Generate(addForeignKeyOperation);
16         } 
17         #endregion
18 
19 
20 }

引用路径:http://q.cnblogs.com/q/65485/

Entity Framework code first设置不在数据库中生成外键

标签:style   blog   http   io   color   sp   for   on   数据   

原文地址:http://www.cnblogs.com/baiyunchen/p/4159905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!