Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

c# - What are the differences between HasOne and References in nhibernate?

What are the differences between HasOne() and References() in nhibernate?

question from:https://stackoverflow.com/questions/1622007/what-are-the-differences-between-hasone-and-references-in-nhibernate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

HasOne creates a one-to-one mapping between tables for you. References creates a typical relational many-to-one relationship.

More defined:

  • a one-to-one relationship means that when one record exists in one table, it must (or can) have one and at most one record in the other referenced table. Example: User table and Options table (one user has one fixed set of options)
  • a many-to-one relationship means that when one records exists in one table, it can have many related records in another table. Example: User table and Purchase table (one user can do many purchases).

Note: where I say table you can replace that safely with class or entity as you wish, when using FluentNH it's easy to use them interchangeably.

This is more precisely explained in this fluentnhibernate wiki article.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...