zoukankan      html  css  js  c++  java
  • Entity Framework code first设置不在数据库中生成外键

    你现在用的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/

  • 相关阅读:
    3.5——课题选择
    3.8——K-th Substring
    01背包dp
    贪心——IQ
    Secret Project Gym
    快速幂&矩阵快速幂
    用栈非递归实现fib数列
    CodeForces Round #590 (Div 3)
    SQL Server常见问题
    SQL基础函数
  • 原文地址:https://www.cnblogs.com/baiyunchen/p/4159905.html
Copyright © 2011-2022 走看看