zoukankan      html  css  js  c++  java
  • 一起谈.NET技术,NHibernate3剖析:Mapping篇之ConfORM实战(5):Component语义 狼人:

      Component语义

      使用ConfORM“映射”组件,我们无需特别设置,ConfORM内部会根据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的映射字符串结果:

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

      在上面Domain的基础上新增一个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的映射字符串结果:

    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的映射字符串结果:

    CollectionOfComponents  4.Bidirectional relation

      实现实体与组件的双向关联关系:

    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的映射字符串结果:

    BidirectionalRelation  结语

      这篇文章展示ConfORM的Components语义应用,映射了一些Domain示例。接下来继续介绍ConfORM。Are you ConfORM?

      参考资料

      Fabio Maulo:ConfORM:“Mapping” Components

  • 相关阅读:
    JS实现继承的几种方式
    跨平台APP----对Cordova,APPCan,DCloud,APICloud四大平台的分析
    cordova生成的android项目导入到Android studio 2.X 中遇到的问题解决方案
    链操作相关命令(包括启动,重启,删除)
    冷钱包和热钱包有什么区别?
    常用命令之git/linux
    centos安装git,go,shasum,okexchain环境
    iterm2的下载安装与配置
    使用jsdoc-to-markdown提前js文件的文档
    基于sphinx的文档(一)将md转为rst
  • 原文地址:https://www.cnblogs.com/waw/p/2162793.html
Copyright © 2011-2022 走看看