Nhibernate 및 Microsoft SQL Server로 개발 된 응용 프로그램을 가지고 있지만 이제는 SQLite로 마이그레이션하려고합니다. SQLite에 문제가 있음을 발견했습니다. 적절한 고정 소수점 숫자 형식과 정확한 금액 계산을 제공하지 않습니다. 그래서이 문제를 해결하기 위해 사용자 정의 IResultTransformer 및 UserType (FixedPointDecimalUserType)을 작성하는 고정 소수점 동작을 시뮬레이트합니다. 또한 응용 프로그램간에 매핑을 공유하려고합니다.nhibernate UserTypes를 주입하기위한 프로그래밍 방식이 있습니까?
내가 유형은 소수이고 속성과 구성 요소에 매핑 내 UserType을 주입하는 확장자가
<property name="Quantity" not-null="true" type="Decimal(8,3)"/>
내 확장은 다음과 같이이다 : 나는 NHibernate.Mapping을 찾을 때
public static class NHExtensions
{
public static NHibernate.Cfg.Configuration AdaptToSQLite(this NHibernate.Cfg.Configuration configuration)
{
if (configuration.ClassMappings.Count == 0)
throw new InvalidOperationException("Es necesario añadir el assembly al configuration antes de llamar a este método");
if (configuration.Properties[NHibernate.Cfg.Environment.Dialect].IsIn(typeof(SQLiteDialect).FullName, typeof(SQLiteDialect).AssemblyQualifiedName))
{
foreach (var mapping in configuration.ClassMappings)
foreach (var property in mapping.PropertyIterator)
AdaptProperty(property);
foreach (var mapping in configuration.CollectionMappings)
How to get inject FixedPointUserType?
}
return configuration;
}
public static void AdaptProperty(Property property)
{
if (property.IsComposite)
{
var component = property.Value as Component;
component.PropertyIterator.Each(AdaptProperty);
}
if (property.Type.GetType() == typeof(DecimalType))
{
var simpleValue = property.Value as SimpleValue;
if (simpleValue != null)
simpleValue.TypeName = typeof(FixedPointDecimalUserType).AssemblyQualifiedName;
}
}
}
을하지만. List <> 내 UserType을 삽입하는 방법을 모르겠습니다 (예 : 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는 응용 프로그램에 대해 다른 사용자 정의 UserType을 구현하고 내 .hbm 파일
<property name="Quantity" not-null="true" type="FixedPointUserType"/>
의 모든 소수점 유형을 대체 할 수도 있지만? 사전에
감사