Getting NHibernate to generate a HiLo string ID
We've got a large system that's loosely bound to its data source (Navision) via Unity - we're getting the opportunity to swap it out and have our own database.
So we've had a look around and really like the look of Fluent NHibernate - we're trying to get a proof of concept going and swap out a couple of the services.
We want to use NHibernates HiLo algorithm - Unfortunately we've inherited string ID's from Navision which prefixs its ID's (example COL00001) so to match the Interface we need to use string Id's.
Does anyone know how I'd get something like ...
Id(x => x.ID).GeneratedBy.HiLo("100");
working where ID is a string? We're currently getting Identity must be int, long etc
Thanks,
Andy
------ Update ------
I tried the example in the article suggested but this functionality has been removed from later versions of Fluent NHibernate - there is however a .Custom - but I can't seem to get it working!
public class ManufacturerMap : ClassMap<Manufacturer>
{
public ManufacturerMap()
{
Id(x => x.ID).GeneratedBy.Custom(typeof(StringTableHiLoGenerator));
Map(x => x.Name);
}
}
public class StringTableHiLoGenerator : TableHiLoGenerator
{
public override object Generate(ISessionImplementor session, object obj)
{
return base.Generate(session, obj).ToString();
}
}
Finally cracked it ... thanks for you assistance - heres the solution in case anyones interested?
Note that in the Configure method the IType has to be passed to the base as an int.
public class ManufacturerMap : ClassMap<Manufacturer>
{
public ManufacturerMap()
{
Id(x => x.ID).GeneratedBy.Custom<StringTableHiLoGenerator>(a => a.AddParam("max_lo", Nexus3General.HiLoGeneratorMaxLoSize.ToString()));
Map(x => x.Name);
}
}
public class StringTableHiLoGenerator : TableHiLoGenerator
{
public override object Generate(ISessionImplementor session, object obj)
{
return base.Generate(session, obj).ToString();
}
public override void Configure(IType type, System.Collections.Generic.IDictionary<string, string> parms, NHibernate.Dialect.Dialect dialect)
{
base.Configure(NHibernateUtil.Int32, parms, dialect);
}
}
Getting NHibernate to generate a HiLo string ID的更多相关文章
- 解决java.lang.NumberFormatException: For input string: "id"
今天,项目突然报"java.lang.NumberFormatException:For input string:"id"",项目框架是spring,spri ...
- Page.FindControl(string id) 与母版页结合后发现的一个问题
MSDN上解释Page.FindControl(string id)方法用于查找指定ID的控件.例如: <asp:TextBox id="Email" runat=" ...
- Spring源码入门——DefaultBeanNameGenerator解析
我们知道在spring中每个bean都要有一个id或者name标示每个唯一的bean,在xml中定义一个bean可以指定其id和name值,但那些没有指定的,或者注解的spring的beanname怎 ...
- <context:component-scan>详解
默认情况下,<context:component-scan>查找使用构造型(stereotype)注解所标注的类,如@Component(组件),@Service(服务),@Control ...
- 【Spring源码分析】配置文件读取流程
前言 Spring配置文件读取流程本来是和http://www.cnblogs.com/xrq730/p/6285358.html一文放在一起的,这两天在看Spring自定义标签的时候,感觉对Spri ...
- Spring源码分析:Bean加载流程概览及配置文件读取
很多朋友可能想看Spring源码,但是不知道应当如何入手去看,这个可以理解:Java开发者通常从事的都是Java Web的工作,对于程序员来说,一个Web项目用到Spring,只是配置一下配置文件而已 ...
- <context:component-scan>详解 转发 https://www.cnblogs.com/fightingcoding/p/component-scan.html
<context:component-scan>详解 默认情况下,<context:component-scan>查找使用构造型(stereotype)注解所标注的类,如@ ...
- springMVC拦截配置
1.web.xml文件配置 <!-- spring mvc --> <servlet> <servlet-name>DispatcherServlet</se ...
- Spring源码入门——DefaultBeanNameGenerator解析 转发 https://www.cnblogs.com/jason0529/p/5272265.html
Spring源码入门——DefaultBeanNameGenerator解析 我们知道在spring中每个bean都要有一个id或者name标示每个唯一的bean,在xml中定义一个bean可以指 ...
随机推荐
- c/c++工程中外部头文件及库添加方法
在VS工程中,添加c/c++工程中外部头文件及库的基本步骤: 1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录. 2.添加文件引用 ...
- VS2012打包部署Winform程序
打包前的准备工作: 新建一个打包部署项目,点OK,如果是第一次使用的话,会打开一个网页,按照提示的步骤来做, 点击上面的step2的网址,进入到另一个网页: 填写完右边的信息,点击“download ...
- c++数组、字符串操作
一.数组操作 1.数组初始化1-1一维数组初始化:标准方式一: int value[100]; // value[i]的值不定,没有初始化标准方式二: int value[100] = {1,2}; ...
- 如何通过Android Studio发布library到jCenter和Maven Central
http://www.jianshu.com/p/3c63ae866e52# 在Android Studio里,如果你想引入任何library到自己的项目中,只需要很简单的在module的build. ...
- UDP广域网,局域网通信-原理分析,穿透技术
一.UDP局域网通信. 这个比较简单,关于局域网中的2台或者更多的计算机之间的UDP通信,网络上一大把,直接复制粘贴就可以使用,原理也非常简单.所以,本文不做详细介绍. 二.UDP广域通信(包括路由器 ...
- javascript —— HTTP头文件详解
HTTP(超文本传输协议:HyperText Transfer Protocol)是浏览器和服务器通过internet进行相互通信的协议,也是网络上应用最为广泛的一种网络协议.HTTP规范由World ...
- 第三百二十八天 how can I 坚持
今天电脑快把我搞疯了,一天得死机快十次,不知道怎么回事,最后升级了win10,感觉就是比较好. 哎,成了这个样子,当初为什么又让我抽中了那个签,搞不懂啊,这都是为啥. 我哪里错了,还是冥冥中自有天意, ...
- UVALive 7077 - Song Jiang's rank list(模拟)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 代码SketchPaintCode绘制
作者:codeGlider 在我的上一篇文章中 swift10分钟实现炫酷的导航控制器跳转动画,有一个swift logo的形状 上一篇文章的动画 我说的就是中间用来做遮罩的形状. 它不是图片是用一段 ...
- POJ1948Triangular Pastures(DP)
POJ1948http://poj.org/problem?id=1948 题目大意就是说给你n个木棍让你用它们摆成一个三角形 使得这个三角形的面积最大. 这个题我之前想的时候一直纠结怎么通过之前的 ...