博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一起谈.NET技术,NHibernate3剖析:Mapping篇之ConfORM实战(5):Component语义
阅读量:7154 次
发布时间:2019-06-29

本文共 2134 字,大约阅读时间需要 7 分钟。

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

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

  3.Collection of components

  使用一个集合,而不是单一组件:

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

  Mapping

  输出HbmMapping的映射字符串结果:

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

  结语

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

  参考资料

  Fabio Maulo:

转载于:https://www.cnblogs.com/waw/archive/2011/09/01/2162793.html

你可能感兴趣的文章
Aqua Data Studio 查询结果中文乱码
查看>>
2016第21周三问题记录
查看>>
软件开发过程模型
查看>>
CloudFlare Support - Error 522: Connection timed out 错误522:连接超时
查看>>
Maven项目环境搭建实例.
查看>>
Atitit.信息论原理概论attilax总结
查看>>
Openfire 的安装和配置
查看>>
好,开始没做出来 guess-number-higher-or-lower-ii
查看>>
[LeetCode] Find Right Interval 找右区间
查看>>
igbinary vs serialize vs json_encode
查看>>
禅与摩托车维修的艺术
查看>>
TestNG的简单使用
查看>>
数组可以容纳多少水----------给你出道题
查看>>
飘逸的python - 增强的格式化字符串format函数
查看>>
C# 读取EXCEL文件的三种经典方法
查看>>
防DNS劫持教程,手动修复本地DNS教程
查看>>
java8_api_net
查看>>
wget: command not found
查看>>
C#九九乘法表的算法
查看>>
开篇:解决IE9字体模糊的问题(又称无法关闭ClearType)
查看>>