public void ComponentMappingDemo()
{
//show how " /> 久久久欧美,久久综合九色,欧美a区

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

NHibernate3剖析:Mapping篇之ConfORM實戰(zhàn)(5):Component語義

  Component語義

  使用ConfORM“映射”組件,我們無需特別設(shè)置,ConfORM內(nèi)部會根據(jù)Domain定義來判定組件,一般而言,沒有主鍵的類就是組件。

[Test]
public void ComponentMappingDemo()
{
//show how work with components and how ConfORM understands OOP
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm);
//use the definition of table-to-class strategy class by class
orm.TablePerClass<Person>();
// Show the mapping to the console
var mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
Console.Write(mapping.AsString());
}

  一些Domain范例

  我們使用各種集合定義Domain:

  1.Mapping a class with components

  Person實體有兩個組件:

public class Person
{
public int Id { get; set; }
public Name Name { get; set; }
public Address Address { get; set; }
}

public class Name
{
public string First { get; set; }
public string Last { get; set; }
}
public class Address
{
public string Street { get; set; }
public int CivicNumber { get; set; }
}

  Mapping

  輸出HbmMapping的映射字符串結(jié)果:

ClassWithComponents  2.Mapping a class with double usage of same component

  在上面Domain的基礎(chǔ)上新增一個Name類型的屬性:

public class Person
{
public int Id { get; set; }
public Name Name { get; set; }
public Name ShowBusinessAlias { get; set; }
public Address Address { get; set; }
}

  Mapping

  輸出HbmMapping的映射字符串結(jié)果:

ClassWithDoubleSameComponents  3.Collection of components

  使用一個集合,而不是單一組件:

public class Person
{
private Iesi.Collections.Generic.ISet<Address> addresses;
public Person()
{
addresses = new Iesi.Collections.Generic.HashedSet<Address>();
}
public int Id { get; set; }
public Name Name { get; set; }
public ICollection<Address> Addresses { get { return addresses; } }
}

  Mapping

  輸出HbmMapping的映射字符串結(jié)果:

CollectionOfComponents  4.Bidirectional relation

  實現(xiàn)實體與組件的雙向關(guān)聯(lián)關(guān)系:

public class Person
{
public int Id { get; set; }
public Name Name { get; set; }
public Name ShowBusinessAlias { get; set; }
public Address Address { get; set; }
}
public class Name
{
public Person Person { get; set; }
public string First { get; set; }
public string Last { get; set; }
}

  Mapping

  輸出HbmMapping的映射字符串結(jié)果:

BidirectionalRelation  結(jié)語

  這篇文章展示ConfORM的Components語義應用,映射了一些Domain示例。接下來繼續(xù)介紹ConfORM。Are you ConfORM?

  參考資料

  Fabio Maulo:ConfORM:“Mapping” Components

NET技術(shù)NHibernate3剖析:Mapping篇之ConfORM實戰(zhàn)(5):Component語義,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 小矮人在线观看完整版| 贝子鸟叫声十三口| 电影终结者| 儿子给妈妈过生日,妈妈幸福感言| 高潮艺术| 森林运动会作文三年级300字| 《我的太阳》电视剧| 电影男女| 一级特黄新婚之夜| 迷失之城剧情介绍| 古风男头| 德鲁| 赏金猎人日本电影完整版| 带圈序号1-50| 免费看网站| 颂文| 浙江卫视今晚上8点的节目是什么| 帕巴拉呼图克图| 寡妇高潮一级免费看| 蓝莓之夜 电影| 张振铎| 那些年简谱| 安静书素材可打印| chinese国产xxx实拍| 卜冠今| 李洋演员| 行李箱品牌排行榜前十名| 托比蜘蛛侠| 髋关节置换术后护理ppt | 超越演员表| 满天星的电影都有哪些| 滨美枝| 妈妈的朋字韩剧| 土力学| 白璐个人简介照片| 红白黑黄| 押韵表实用大全| 邯郸恋家网| 意外的春天| 小丑回魂| 声优闺蜜小涵|