nhibernate GetType
本原理 /* This code assumes an IEntity interface that identifies your persistent types. */
/// <summary>
/// This static class provides common extension methods for <see cref="IEntity"/> types.
/// </summary>
public static class EntityExtensions {
/// <summary>
/// Gets the real, underlying Entity-type - as opposed to the standard GetType() method,
/// this method takes into account the possibility that the object may in fact be an
/// NHibernate Proxy object, and not a real object. This method will return the real
/// Entity-type, doing a full initialization if necessary.
/// </summary>
public static Type GetEntityType(this IEntity entity ) {
if(entity is INHibernateProxy)
{ var lazyInitialiser = ((INHibernateProxy)entity).HibernateLazyInitializer;
var type = lazyInitialiser.PersistentClass;
if( type.IsAbstract || type.GetNestedTypes().Length > )
return Unproxy ( entity ).GetType ();
else // we don't need to "unbox" the Proxy-object to get the type
return lazyInitialiser.PersistentClass ;
}
return entity.GetType ();
}
/// <summary>
/// Based on the real, underlying Entity-type, this method returns true if the specified
/// type matches (or is assignable from) the specified Type.
/// </summary>
public static bool Is < TEntity >( this IEntity entity ) where TEntity : class , IEntity
{
var entityType = entity.GetEntityType ();
var type = typeof ( TEntity );
return entityType == type || type.IsAssignableFrom ( entityType );
} /// <summary>
/// In some cases, you may need the actual object, not just the type - for example, if
/// you're going to cast to a type deeper in the hierarchy, you may need to Unproxy
/// the object first.
/// </summary>
public static TEntity Unproxy < TEntity >( this TEntity entity ) where TEntity : class , IEntity
{
return entity is INHibernateProxy ? (TEntity)Service.Session.GetSessionImplementation ().PersistenceContext.Unproxy(entity ):entity ;
}
}
nhibernate GetType的更多相关文章
- 全自动迁移数据库的实现 (Fluent NHibernate, Entity Framework Core)
在开发涉及到数据库的程序时,常会遇到一开始设计的结构不能满足需求需要再添加新字段或新表的情况,这时就需要进行数据库迁移. 实现数据库迁移有很多种办法,从手动管理各个版本的ddl脚本,到实现自己的mig ...
- 配置NHibernate将枚举保存为Oracle数据库中的字符串
假设有这样一个枚举: /// <summary> /// 字典项类型 /// </summary> public enum DicItemType { [EnumDescrip ...
- 5、ASP.NET MVC入门到精通——NHibernate代码映射
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 上一篇NHibernate学习笔记—使用 NHibernate构建一个ASP.NET MVC应用程序 使用的是xml进行orm映射,那么这一 ...
- 测试 ClownFish、CYQ、Entity Framework、Moon、MySoft、NHibernate、PDF、XCode数据访问组件性能
下期预告: 由于很多园友反馈,有的组件不应该缺席.测试复杂度不够.测试还缺乏一定的公平. 因此考虑在下一个版本中,确保在更加公平的前提下进行更高复杂度的测试 . 同时将分为2组测试,纯SQL组件及纯O ...
- How to implement a custom type for NHibernate property
http://blog.miraclespain.com/archive/2008/Mar-18.html <?xml version="1.0" encoding=&quo ...
- csharp:Nhibernate Procedure with CreateSQLQuery and GetNamedQuery
<?xml version="1.0" encoding="utf-8"?> <hibernate-mapping assembly=&quo ...
- NHibernate实例化类部分属性
NHibernate 为习惯SQL的开发者提供了接口,将查询的结果转变为持久化对象.虽然该方法不是很提倡. GetCurrentSession().CreateSQLQuery(sql) 参数sql就 ...
- MyGeneration模板生成NHibernate映射文件和关系(one-to-one,one-to-many,many-to-many)
MyGeneration的几个NHibernate模板功能已经很强,但还是存在些问题.例如:Guid主键支持不佳,代码不易修改,不支持中文注释等等.所以我决定自己来改写此模版.我把一部分通用的函数提取 ...
- Nhibernate cookbook 3.0-翻译
/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...
随机推荐
- Exce信息提取
Exce信息提取 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Sub 信息汇总( ...
- CSS各浏览器HACK
/*firefox*/@-moz-document url-prefix(){.mainNews div.l ul{padding-bottom:12px}} /*ie6*/{_padding:2px ...
- Java虚拟机(一)之开篇
写此类文章的初始动机:被同事问道 jvm 是做什么时,竟然茫然以对: 按照惯例,从 what/where/how 等开篇,即: 一. JVM 的目的是什么? 二. JVM 是什么时候被以何总形式被安装 ...
- java代码---------实现File的目录下创建文本文档
总结:虽然他没教给我们很多,但是他已经很棒了 package com.a.b; import java.io.*; public class dd { public static void main( ...
- Java-API-POI:POI 笔记
ylbtech-Java-API-POI:POI 笔记 1. 笔记一返回顶部 1. 1,POI对JDK版本支持及XLSX (2017-04-01 13:51:39)对JDK6的支持,最后版本是POI- ...
- DBA_2PC_PENDING (转)
DBA_2PC_PENDINGOracle会自动处理分布事务,保证分布事务的一致性,所有站点全部提交或全部回滚.一般情况下,处理过程在很短的时间内完成,根本无法察觉到.但是,如果在commit或rol ...
- Promise题目
setTimeout(function () { console.log(1); }, 0) new Promise(function executor(resolve) { console.log( ...
- 转 Quartz将Job持久化所需表的说明
QRTZ_CALENDARS 以 Blob 类型存储 Quartz 的 Calendar 信息 QRTZ_CRON_TRIGGERS 存储 Cron Trigger,包括 Cron表达式和时区信息 ...
- Spring Boot实践——Filter实现
Filter介绍 Filter是Servlet规范规定的,不属于spring框架,也是用于请求的拦截.但是它适合更粗粒度的拦截,在请求前后做一些编解码处理.日志记录等. 一个Filter包括:1).在 ...
- 安装sql server 2000
昨天下午快下班的时候 因为公司需要折腾了下sql server 2000,先不说这么古老的版本,而且安装的也是醉了... 首先sql server 2000是基于32位的系统开发的,那时候据说还没有6 ...