http://blog.miraclespain.com/archive/2008/Mar-18.html

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SoftInn.Domain" > <class name="SoftInn.Domain.Archives.Archive" table="archive" lazy="false">
<!--Mapped classes must declare the primary key column of the database table.
Most classes will also have a property holding the unique identifier of an instance.
The <id> element defines the mapping from that property to the primary key column.-->
<id name="Id" column="archive_id" type="Int64">
<!--"column" is The name of the primary key column-->
<generator class="SoftInn.Services.Internal.NHibernate.IdGenerator, SoftInn.Services">
<param name="table">nextinstanceid</param>
<param name="column">next</param>
<param name="max_lo">9</param>
</generator>
</id> <version name="LastUpdateNumber" column="last_update_number" type="Int32" unsaved-value="-1"/>
<component name="OwnerId" class="SoftInn.Domain.ObjectId">
<property name="ClassId" column= "node_type" type="Int32"/>
<property name="InstanceId" column= "node_id" type="Int64"/>
</component> <property name="User" type="SoftInn.Services.Internal.NHibernate.UserType, SoftInn.Services" not-null="false">
<column name="siuser_id"/>
</property>

<property name="FullName" column= "full_name" type="String"/>
<property name="Name" column= "archive_name" type="String"/>
<property name="NodeNamePath" column= "node_name_path" type="String"/>
<property name="Size" column="archive_size" type="Int64"/>
<property name="ZipSize" column="archive_physical_zip_size" type="Int64"/>
<property name="ContainsReports" column="contains_reports" type="YesNo"/>
<property name="ContainsPermissions" column="contains_permissions" type="YesNo"/>
<property name="FilteredByDateRange" column="is_filteredby_data_range" type="YesNo"/>
<property name="StartDate" column= "start_datetime" type="SoftInn.Services.Internal.NHibernate.DateTimeType, SoftInn.Services"/>
<property name="EndDate" column= "end_datetime" type="SoftInn.Services.Internal.NHibernate.DateTimeType, SoftInn.Services"/>
<component name="PermissionOwnerId" class="SoftInn.Domain.ObjectId">
<property name="ClassId" column= "permissionowner_type" type="Int32"/>
<property name="InstanceId" column= "permissionowner_id" type="Int64"/>
</component>
<property name="PermissionOwnerName" column= "permissionowner_name" type="String"/>
<property name="CreateDate" column= "create_datetime" type="SoftInn.Services.Internal.NHibernate.DateTimeType, SoftInn.Services"/>
<property name="Status" column= "status" type="String"/>
</class> </hibernate-mapping>
namespace SoftInn.Services.Internal.NHibernate {

    /// <summary>
/// Used to retrieve and store generic User object relationships via an "InstanceId" column
/// </summary>
public class UserType : BaseEntityType { /// <see cref="SoftInn.Services.Internal.NHibernate.BaseEntityType.ReturnedClass"/>
public override Type ReturnedClass {
get { return typeof(User); }
}
}
}

  

using System;
using NHibernate;
using NHibernate.Engine;
using NHibernate.Type;
using NHibernate.UserTypes;
using SoftInn.Domain;
using SoftInn.Platform.Log; namespace SoftInn.Services.Internal.NHibernate { /// <summary>
/// Abstract base class for classes used to retrieve and store
/// generic Persistent object relationships via an "InstanceId" column.
/// </summary>
public abstract class BaseEntityType : ICompositeUserType { #region ICompositeUserType Members /// <summary>See base class documentation</summary>
public string[] PropertyNames {
get { return new String[] { "InstanceId" }; }
} /// <summary>See base class documentation</summary>
public IType[] PropertyTypes {
get {
return new IType[] { NHibernateUtil.Int64 };
}
} /// <summary>See base class documentation</summary>
public abstract Type ReturnedClass {
get;
} /// <summary>See base class documentation</summary>
public object Assemble(object cached, ISessionImplementor session, object owner) {
return DeepCopy(cached);
} /// <summary>See base class documentation</summary>
public object DeepCopy(object value) {
return value;
} /// <summary>See base class documentation</summary>
public object Disassemble(object value, ISessionImplementor session) {
return DeepCopy(value);
} /// <summary>See base class documentation</summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
public object GetPropertyValue(object component, int property) {
if (component == null) {
throw new ArgumentNullException("component");
} if (property == 0) {
return ((Entity)component).ObjectId.InstanceId;
} else {
return null;
}
} /// <summary>See base class documentation</summary>
public bool IsMutable {
get { return true; }
} /// <summary>See base class documentation</summary>
public object NullSafeGet(System.Data.IDataReader dr, string[] names, ISessionImplementor session, object owner) {
object instanceIdObj = NHibernateUtil.Int64.NullSafeGet(dr, names[0], session, owner); if (instanceIdObj == null ) {
// Null instanceId means a null entity reference.
return null;
} Int64 instanceId = (Int64)instanceIdObj; // Construct an ObjectId for this instanceId.
ObjectId entityId = new ObjectId(ReturnedClass, instanceId); try {
// Find and return the corresponding Entity object.
return ServiceDirectory.PersistServices.FindById(entityId, true); } catch (SoftInn.Services.Exceptions.ObjectNotFoundException) {
// The referenced entity no longer exists, but we still have a reference to it by ID.
LogManager.LogError(ServicesLogMessages.LOG_CONTEXT,
ServicesLogMessages.PERSIST_MISSING_OBJECT,
null, entityId.ToString(), GetType().FullName + ".NullSafeGet");
//throw;
return null;
}
} /// <summary>See base class documentation</summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "index+1")]
public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index, ISessionImplementor session) { Entity entity = (value == null) ? null : (Entity)value; if (entity != null && entity.ObjectId != null) {
// Entity with an ObjectId... store the instance id and class id.
Int64 instanceId = entity.ObjectId.InstanceId;
NHibernateUtil.Int64.NullSafeSet(cmd, instanceId, index, session); } else {
// Null entity... store null instance id and class id.
NHibernateUtil.Int64.NullSafeSet(cmd, null, index, session);
}
} /// <summary>See base class documentation</summary>
public void SetPropertyValue(object component, int property, object value) {
} #endregion /// <summary>See base class documentation</summary>
public new bool Equals(object obj1, object obj2) {
if (obj1 == null) {
return obj2 == null;
} else {
return obj1.Equals(obj2);
}
} /// <summary>See base class documentation</summary>
public int GetHashCode(object obj1) {
if (obj1 != null) {
return obj1.GetHashCode();
}
else {
return this.GetHashCode();
}
} /// <summary>See base class documentation</summary>
public object Replace(object original, object target, ISessionImplementor session, object owner) {
return original;
} }
}

  

How to implement a custom type for NHibernate property的更多相关文章

  1. Binding a Xamarin.Forms WebView to ReactiveUI View Model using Custom Type Converters

    引用:https://jamilgeor.com/binding-a-xamarin-forms-webview-to-reactiveui-view-model-using-custom-type- ...

  2. How to: Implement a Custom Base Persistent Class 如何:实现自定义持久化基类

    XAF ships with the Business Class Library that contains a number of persistent classes ready for use ...

  3. 09.AutoMapper 之自定义类型转换器(Custom Type Converters)

    https://www.jianshu.com/p/47054d92db2a 自定义类型转换器(Custom Type Converters) 有时需要完全控制一种类型到另一种类型的转换.这一般发生在 ...

  4. org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'null' to required type 'double' for property 'band'; nested exception is org.springframework.core.convert.Con

    本文为博主原创,未经允许不得转载: 先将异常粘贴出来: 20:37:26,909 ERROR [com.suning.fucdn.controller.ProductDataStaticsContro ...

  5. [Angular] Implement a custom form component by using control value accessor

    We have a form component: <label> <h3>Type</h3> <workout-type formControlName=& ...

  6. [TypeScript] Define Custom Type Guard Functions in TypeScript

    One aspect of control flow based type analysis is that the TypeScript compiler narrows the type of a ...

  7. [Angular 8] Implement a Custom Preloading Strategy with Angular

    Preloading all modules is quite an extreme approach and might not always be desirable. For instance, ...

  8. How to implement a custom PropertyEditor so that it supports Appearance rules provided by the ConditionalAppearance module

    https://www.devexpress.com/Support/Center/Question/Details/T505528/how-to-implement-a-custom-propert ...

  9. Changing the type of a property with EF Code First

    The smartest way is probably to not alter types. If you need to do this, I'd suggest you to do the f ...

随机推荐

  1. datagridview随窗体的大小而变,表格填满控件

    在C#winform布局的时候,我们拖一个datagridview到窗体上面,将datagridview调整为适合窗体的大小,但是我们运行之后,点击最大化按钮的时候,却发现datagridview的大 ...

  2. C#使用DataSet Datatable更新数据库的三种实现方法

    本文以实例形式讲述了使用DataSet Datatable更新数据库的三种实现方法,包括CommandBuilder 方法.DataAdapter 更新数据源以及使用sql语句更新.分享给大家供大家参 ...

  3. 【原创】js中利用cookie实现记住密码功能

    在登录界面添加记住密码功能,我首先想到的是在java后台中调用cookie存放账号密码,大致如下: HttpServletRequest request HttpServletResponse res ...

  4. 错误,这个如何解决呢?内存溢出的问提。把JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m 还是不行

    java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at ja ...

  5. 系统巡警 v1.2 系统行为分析神器

    系统巡警,是一款安全辅助软件,可以帮助系统维护人员或安全研究人员观察系统运行情况,包括进程启动与销毁记录.模块加载记录.线程启动与销毁记录.系统服务创建修改和删除记录.文件与文件夹的增加删除和修改记录 ...

  6. LuaStudio 9.27 去10分钟退出暗桩板

    http://bbs.pediy.com/showthread.php?p=1428203#post1428203

  7. 特征创建:Reference Characteristic、Template

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. 描述Linux运行级别0-6的各自含义

    中文: 0: 关机模式 1:单用户模式<==破解root密码 2:无网络支持的多用户模式 3:有网络支持的多用户模式(文本模式,工作中最长使用的模式) 4:保留,未使用 5:有网络支持又x-wi ...

  9. CSS设置透明的两种方式

    1..demo{ background-color:transparent; } 2..demo{ background-color:rgba(0,0,0,0.5); //最后一个参数是用来设置透明度 ...

  10. BWT (Burrows–Wheeler_transform)数据转换算法

    1.什么是BWT 压缩技术主要的工作方式就是找到重复的模式,进行紧密的编码. BWT(Burrows–Wheeler_transform)将原来的文本转换为一个相似的文本,转换后使得相同的字符位置连续 ...