zoukankan      html  css  js  c++  java
  • Foreign Keys in the Entity Framework

    原文:http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx

    How do I create an "FK Association"?   添加外键关联

    There are a number of ways.

    One mainline scenario is when using the tools to infer a model from a database. We have added an option to choose whether "FK Associations" or "Independent Associations" are generated by default. The same is true if you use EdmGen.exe (i.e. our command line tool).

    The second mainline scenario for creating FK Associations is creating a model from scratch, aka Model First which is new to .NET 4.0.

    Here are the steps involved:

    1. Create two Entities (say Product and Category) that look something like this:

      ProductCategoryStep1

    2. Add a property that will be the FK Property: i.e. CategoryID

      ProductCategoryStep2

    3. Create an association between the two EntityTypes with the correct end multiplicities and NavigationProperty names:

      ProductCategoryStep3

    4. Double Click the line between the two Entities, that represents the Association, and add a Referential Integrity Constraint:

      ProductCategoryStep4
      This is the step that tells the Entity Framework that the CategoryID is an "FK Property" and that the "CategoryProduct" association is an "FK Association".

    5. You end up with something that looks like this:

      ProductCategoryStep5 

    And you are done you've set up an FK Association. Notice that this association doesn't need to be mapped you simply need to make sure you map all the properties of both Entities.

    Very easy.

  • 相关阅读:
    TCMalloc 内存分配原理简析
    技术人沟通中的几个常见问题
    不同路径
    Js将字符串转数字的方式
    防抖节流模式
    Location对象
    React生命周期
    fgrep命令
    数据访问对象模式
    保持城市天际线
  • 原文地址:https://www.cnblogs.com/jifsu/p/1736465.html
Copyright © 2011-2022 走看看