• 添加Net4CollectionTypeFactory的原因


    .NET4.0已经实现了该功能

     http://jahav.com/blog/nhibernate-using-net-4-iset/

    NHibernate using .NET 4 ISet

    NHibernate 4.0 (released in 2014-08-17) has brought us support for .NET 4 ISet<> collections, thus freeing us from the tyranny of the Iesi package. But long before that, there was a way to use .NET 4 ISet in you NHibernate 3 projects:

    NHibernate.SetForNet4

    SetForNet4 is a NuGet package you can install into your application. Once you install it, there will be a new file with a implementation of a ICollectionTypeFactory in your project that will support System.Collections.Generic.ISet<> instead of Iesi.Collections.Generic.ISet<>. Other than that, it is basically a copy of the original DefaultCollectionTypeFactory.

    All you need to do after installation is to set the configuration property “collectiontype.factory_class” to the assembly qualified name of the created factory, make sure the dll with the created collection factory can be loaded (if you have it in separate project) and all will be peachy.

    I had slight trouble with configuration, I have configuration spread over the XML and the code and the comment at the top said to add line to my configuration:

    //add to your configuration: 
    //configuration.Properties[Environment.CollectionTypeFactoryClass] 
    //        = typeof(Net4CollectionTypeFactory).AssemblyQualifiedName

    Since it was integral part of the configuration (not the db dialect or something), I put it to the code

    var configuration = new Configuration().Configure(); 
    configuration.Properties[Environment.CollectionTypeFactoryClass] 
         = typeof(Net4CollectionTypeFactory).AssemblyQualifiedName; 

    … and it didn’t work. I had to set the factory before I made configured from XML.

    var configuration = new Configuration() 
        .SetProperty(Environment.CollectionTypeFactoryClass, typeof(Net4CollectionTypeFactory).AssemblyQualifiedName) 
        .Configure()

    I am not exactly sure why, but I think it is because I also have assemblies with *hbm.xml mapping files specified in the XML using <mapping assembly="EntityAssembly" /> tags.

    The configuration code have set the collection factory of the bytecode provider before the mapped assemblies were processed.

    Downside

    It should be noted that using SetForNet4 package, you can’t use both, the Iesi and the .NET4 collections at the same time, thus you need to replace the Iesi in the whole application. Also, we have NH 4.0 now, so doing this is kind of pointless, but I did it before 4.0 and I don’t have time to upgrade to 4.0 and check that my app still works as advertised.

  • 相关阅读:
    python常用模块
    清除在Windows下访问共享文件夹时的登录信息
    CentOS 6.3下Samba服务器的安装与配置
    textarea定位光标
    js中apply方法的使用
    js call方法
    linux 安装svn,并设置钩子来同步更新
    mysql给root开启远程访问权限,修改root密码
    在VMware的Linux系统上安装Redis
    (转)NoSQL——Redis在win7下安装配置的学习一
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/4658168.html
Copyright © 2020-2023  润新知