Nbearv3--orm Entity Relationship Design Quick Reference manual

Source: Internet
Author: User
Tags manual inheritance

Version

1.2 [2006-11-13]

Brief introduction

This guide shows a complete reference to all the entity relationship designs supported by NBearV3. A design method that includes 1 pairs of 1,1, many-to-many associations, and all cases of autocorrelation forward and reverse references.

Note 1: This manual does not discuss inheritance relationships. Because the inheritance relationship naturally maps to the inheritance of the design entity interface, there is no need for much additional discussion.

Note 2: All associations include both forward and reverse read-write references in the demo. In actual projects, it is not always necessary to have both forward and reverse references, you can include references in only one direction, or one side contains references, the other contains only a foreign key ID, or it can contain only read-only references. Also, in bidirectional references, it is absolutely not possible to set both bidirectional Lazyload=false.

Note 3: The properties of forward or reverse references in all association relationships, as needed, can be added to Containedattribute identities to implement cascading updates/deletions of properties and entities that contain attributes. Containedattribute is not included in all references shown in this article, please be aware of adding in the actual project, but do not add containedattribute in both forward and reverse reference properties.

Note 4: Before reading this article, it is recommended that readers read the NBearV3 step by step tutorial--orm to master the basics of ORM in NBearV3.

Code

All class diagrams and code shown in this manual are contained in the Tutorials\entity_relation_manual directory in the NBearV3 latest source code ZIP package that can be downloaded from sf.net. Therefore, if you have any questions in the process of using this manual, you can refer to the code directly.

Body

One, 1 to 1 primary key associations

Analysis: A pair of primary key associations refers to two entities that are associated through the same primary key. A typical association relationship is the Association of user and UserProfile in the figure. Where userprofile cannot be detached from a user with the same primary key value. Therefore, in fact, for UserProfile, its attribute userid is both its PK and an FK associated with the user, and Userprofile.userid should have referential integrity constraints on user.id.

public interface User : Entity
  {
    [PrimaryKey]
    Guid ID { get; set; }
    string Name { get; set; }

    [PkQuery(LazyLoad=true)]
    UserProfile Profile
    {
      get;
      set;
    }
  }

  public interface UserProfile : Entity
  {
    [PrimaryKey]
    [FriendKey(typeof(User))]
    Guid UserID { get; set; }
    string Content { get; set; }

    [PkReverseQuery(LazyLoad = true)]
    User User
    {
      get;
      set;
    }
  }

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.