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++ string的标准函数还是很给力的,代码在最下)
其实把程序用到生活中,真的能节约不少时间!程序的力量是无穷滴! 哥们的毕业设计是要做法律文书匹配之类的东东,有一步是要抽取所有的法律法规名称,而刚好我们要处理的文件中,法规的名称之前都有个‘.‘,所以 ...
- 桶排序-Swift
import Foundation let b:Array = [5,2,3,1,8] var a:NSMutableArray = [] for var i in 0 ..< 11 { a[i ...
- searchBar 隐藏
searchBar 隐藏 CGRect newBounds = self.tableView.bounds; newBounds.origin.y = newBounds.origin.y + _he ...
- 关于使用base36的技巧 生成 优惠券兑换码的相关讨论
关于优惠券的生成后台的制作问题,已经拖了很久了还没有合并.但是持续暴露出来的问题 也很多,我的代码以及前面的一个人的代码被持续review暴露出了大量问题.昨天晚上在
- 应用引擎BAE3.0(转)
add by zhj: 其实我主要是想看看基于docker的PaaS的特性. 原文:http://developer.baidu.com/wiki/index.php?title=docs/cplat ...
- spring 解析配置文件问题
问题描述 2014-02-25 16:39:36.068 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] WARN ...
- Codeforces 583D. Once Again... (LIS变形)
题目链接:http://codeforces.com/contest/583/problem/D 给你t个长度为n的数组.问你最长不下降子序列的长度. 一开始用第一个n数组的lis和最后一个n数组的l ...
- 完整Deploy WebPlayer的Config
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- 用Log4Net记录NHibernate中执行的SQL语句及执行时间
首页,在web.config中加入以下配置: <configuration> <configSections> <section name="log4net&q ...
- DeleteDC() 与 ReleaseDC() 的区别 [转]
DeleteDC 该函数删除指定的设备上下文环境(DC). 原型: BOOL DeleteDC(HDC hdc): 参数: hdc:设备上下文环境的句柄. 返回值: 成功,返回非零值:失败,返回零.调 ...