zoukankan      html  css  js  c++  java
  • 添加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.

  • 相关阅读:
    设计模式-适配器模式(09)
    windows电脑使用技巧及常用CMD
    接口调用方法
    矩阵对角线和
    函数基础小结
    文件处理实战之购物车系统
    文件处理小结
    Python进阶实战之三级菜单
    Python进阶小结
    Python深浅拷贝
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/4658168.html
Copyright © 2011-2022 走看看