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的更多相关文章

  1. 解决java.lang.NumberFormatException: For input string: "id"

    今天,项目突然报"java.lang.NumberFormatException:For input string:"id"",项目框架是spring,spri ...

  2. Page.FindControl(string id) 与母版页结合后发现的一个问题

    MSDN上解释Page.FindControl(string id)方法用于查找指定ID的控件.例如: <asp:TextBox id="Email" runat=" ...

  3. Spring源码入门——DefaultBeanNameGenerator解析

    我们知道在spring中每个bean都要有一个id或者name标示每个唯一的bean,在xml中定义一个bean可以指定其id和name值,但那些没有指定的,或者注解的spring的beanname怎 ...

  4. <context:component-scan>详解

    默认情况下,<context:component-scan>查找使用构造型(stereotype)注解所标注的类,如@Component(组件),@Service(服务),@Control ...

  5. 【Spring源码分析】配置文件读取流程

    前言 Spring配置文件读取流程本来是和http://www.cnblogs.com/xrq730/p/6285358.html一文放在一起的,这两天在看Spring自定义标签的时候,感觉对Spri ...

  6. Spring源码分析:Bean加载流程概览及配置文件读取

    很多朋友可能想看Spring源码,但是不知道应当如何入手去看,这个可以理解:Java开发者通常从事的都是Java Web的工作,对于程序员来说,一个Web项目用到Spring,只是配置一下配置文件而已 ...

  7. <context:component-scan>详解 转发 https://www.cnblogs.com/fightingcoding/p/component-scan.html

    <context:component-scan>详解   默认情况下,<context:component-scan>查找使用构造型(stereotype)注解所标注的类,如@ ...

  8. springMVC拦截配置

    1.web.xml文件配置 <!-- spring mvc --> <servlet> <servlet-name>DispatcherServlet</se ...

  9. Spring源码入门——DefaultBeanNameGenerator解析 转发 https://www.cnblogs.com/jason0529/p/5272265.html

    Spring源码入门——DefaultBeanNameGenerator解析   我们知道在spring中每个bean都要有一个id或者name标示每个唯一的bean,在xml中定义一个bean可以指 ...

随机推荐

  1. Embedded之memory type

    1 Types of memory 2 Characteristics

  2. Flex通信-Java服务端通信实例

    转自:http://blessht.iteye.com/blog/1132934Flex与Java通信的方式有很多种,比较常用的有以下方式: WebService:一种跨语言的在线服务,只要用特定语言 ...

  3. spark的环境安装

    1.安装sbt 正常安装流程. 在cmd里运行的时候,要提前设置代理(如果上网有代理),set JAVA_OPTS=-Dhttp.proxySet=true -Dhttp.proxyHost=172. ...

  4. Linux入门视频

    为了方便新手学习Linux,本人专门录制了以下Linux初级视频方便学习,本系列多媒体教程已完成的博文: 轻松学习Linux之入门篇 http://chenguang.blog.51cto.com/3 ...

  5. 关于网站编码显示问题 效果是 访问 带有中文注释的sass文件出现编码报错。

    首先查看环境变量 export declare -x HOME="/home/piperck" declare -x LANG="en_US.UTF-8" de ...

  6. SharePoint咨询师之路:设计之前的那些事一:容量

    提示:本系列只是一个学习笔记系列,大部分内容都可以从微软官方网站找到,本人只是按照自己的学习路径来学习和呈现这些知识. 咨询师更多的时候是解决方案提供者,那么他们如何能够提供有效的SharePoint ...

  7. 第二百一十七天 how can I 坚持

    JavaScript  document.getElementByName()获取数组,for循环,搞了一天,好笨. 明天要下雪了,好冷. 双十一,天猫搞的挺特别啊,晚上抢了个小米红包,不知道买啥,哎 ...

  8. webrtc 的回声抵消(aec、aecm)算法简介(转)

    webrtc 的回声抵消(aec.aecm)算法简介        webrtc 的回声抵消(aec.aecm)算法主要包括以下几个重要模块:1.回声时延估计 2.NLMS(归一化最小均方自适应算法) ...

  9. codeforces 659A Round House

    A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  10. 原生JS修改标签样式为带阴影效果

    代码如下: JS部分 //点击时候,改变样式 function GetCategoryInfo(value) { var getInfo = value.toString().split(','); ...