Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否有任何编程方法来注入nhibernate用户类型?_Nhibernate_Sqlite_Decimal - Fatal编程技术网

是否有任何编程方法来注入nhibernate用户类型?

是否有任何编程方法来注入nhibernate用户类型?,nhibernate,sqlite,decimal,Nhibernate,Sqlite,Decimal,我有一个使用Nhibernate和Microsoft Sql Server开发的应用程序,但现在我正在尝试将其迁移到SQLite。我发现SQLite有一个问题,它没有给我一个合适的定点数字格式和精确的货币值算法。因此,为了解决这个问题,我模拟了编写自定义IResultTransformer和UserType(FixedPointDecimalUserType)的定点行为。另外,我希望在应用程序之间共享映射 我有一个扩展,可以在类型为decimal的属性和组件映射中插入我的UserType <

我有一个使用Nhibernate和Microsoft Sql Server开发的应用程序,但现在我正在尝试将其迁移到SQLite。我发现SQLite有一个问题,它没有给我一个合适的定点数字格式和精确的货币值算法。因此,为了解决这个问题,我模拟了编写自定义IResultTransformer和UserType(FixedPointDecimalUserType)的定点行为。另外,我希望在应用程序之间共享映射

我有一个扩展,可以在类型为decimal的属性和组件映射中插入我的UserType

<property name="Quantity" not-null="true" type="Decimal(8,3)"/>
但是当我找到一个NHibernate.Mapping.List时,我不知道如何注入我的用户类型,例如对于SoldProduct

<list name="Addins" table="TicketLineAddin" fetch="join">
    <key column="TicketLineId" ..../>
    <index column="AddinIndex"/>
    <composite-element class="Domain.Catalogue.SoldProduct, Domain">
        <property name="ProductId" not-null="true"/>
        <property name="ProductName" not-null="true" length="120"/>
        <property name="Price" not-null="true" type="Decimal(12,3)"/>
        <property name="VatId" column="VatId"  not-null="true"/>
        <property name="VatRate" column="VatRate"  not-null="true" type="Decimal(12,3)"/>
        <property name="PreparationType" not-null="true" type="Common.Ordering.PreparationType, Common"/>
        <property name="PriceListId" not-null="true"/>
        <property name="PrintMode" not-null="true"/>
    </composite-element>
</list>

另一种方法是为SQL Server和SQLite应用程序提供不同的自定义用户类型实现,并替换my.hbm文件中的所有十进制类型

<property name="Quantity" not-null="true" type="FixedPointUserType"/>

但是,是否有任何计划性的方法来解决这个问题

提前感谢foreach(config.CollectionMappings中的var映射)
foreach (var mapping in config.CollectionMappings)
{
    if (mapping.Element.Type.IsComponentType)
    {
        var subtypes = ((ComponentType)mapping.Element.Type).Subtypes;
        for (int i =0; i < subtypes.Length; i++)
        {
            if (subtypes[i].GetType() == typeof(DecimalType))
            {
                subtypes[i] = new FixedPointDecimalUserType();
            }
        }
    }
}
{ if(mapping.Element.Type.IsComponentType) { var子类型=((ComponentType)mapping.Element.Type).subtype; for(int i=0;i
虽然无法测试,但此代码工作正常,谢谢

configuration.BuildMappings();

    ...
foreach(...)
    if (mapping.Element.Type.IsComponentType)
    {
        var subtypes = ((ComponentType)elementType).Subtypes;
        for (var i = 0; i < subtypes.Length; i++)
            if (subtypes[i].GetType() == typeof(DecimalType))
                subtypes[i] = new CustomType(typeof(FixedPointDecimalUserType), new Dictionary<string, string>());

    }
configuration.BuildMappings();
...
foreach(…)
if(mapping.Element.Type.IsComponentType)
{
变量子类型=((ComponentType)elementType).subtype;
对于(var i=0;i
configuration.BuildMappings();

    ...
foreach(...)
    if (mapping.Element.Type.IsComponentType)
    {
        var subtypes = ((ComponentType)elementType).Subtypes;
        for (var i = 0; i < subtypes.Length; i++)
            if (subtypes[i].GetType() == typeof(DecimalType))
                subtypes[i] = new CustomType(typeof(FixedPointDecimalUserType), new Dictionary<string, string>());

    }