NHibernate a pair of relational mappings overview

Source: Internet
Author: User
Tags generator uuid xmlns

The

has two tables: User (user) and blog (set table), and the relationship between them is just as I said a one-to-one relationship. Now we map these two files:

<?xml version= "1.0" encoding= "Utf-8"?>  

Now test how to save the data:

var userdal = new Userdal ();
var blogdal = new Blogdal ();
var user = new user{
                       name = name,
                       Password = Password,
                       posttitle = posttitle,
                       createtime = datetime.now,
  avatar = FileUrl
                   };
var blog = new Blog {user = user};
    
User. blog = blog;
Blogdal.save (blog);
Userdal.save (user);

Summarize:

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/

This succeeded in saving data, made "Laozi" Day time, alas, in fact, hibernate one-to-one association with foreign Key Association, etc., I used this primary key association.

1: If the hibernate set

<id name= "id" >
<column name= "Id" sql-type= "varchar" not-null= "true"/>
<generator class= "Uuid.hex"/>
</id>

Such code, you can not use this code when adding data: Guid.NewGuid. (I didn't know it before, it was a failure).

2:

<generator class= "foreign" >

<param name= "Property" >User</param>

</generator>

This code means that the primary key of the blog refers to the primary key value in the user table.

3: That is, I saved the data, I am not sure if this operation, really a little self-confidence, if Bo friends have some hibernate experts, hope to come in to help me see, is not so save data (important), there are a pair is not such a configuration, alas, Hibernate me to vomit blood.

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.