Tôi đang làm việc lần đầu tiên với FluentNHibernate, cố gắng ánh xạ các lớp học tới cơ sở dữ liệu SQL Express. Nói chung nó hoạt động, nhưng tôi không thể lập bản đồ các loại thuộc tính Đúp hoặc Thập phân cụ thể theo tỷ lệ/độ chính xác quy mô/độ chính xác. Dưới đây cho thấy kết quả cho một thuộc tính duy nhất mà tôi đã kiểm tra lặp đi lặp lại với SchemaUpdate.Execute. Không có trường hợp nào tôi có thể làm cho nó hoạt động.Lập bản đồ FluentNHibernate; Không thể lập bản đồ gấp đôi hoặc thập phân với tỷ lệ/độ chính xác
Sẽ thật sự hữu ích khi nghe một số giải thích cho ánh xạ không hoạt động như tôi mong đợi (2-8)?
// Ok mappings:
1) Decimal: Bản đồ (Function (x) x.Balance) >> thập phân (19, 5)
// Mappings "errors":
2) đúp: Bản đồ (Function (x) x.Balance) .CustomSqlType ("thập phân") >> Thập phân (18,0) - Tại sao độ chính xác 0 là ánh xạ mặc định ở đây?
3) đúp: Bản đồ (Function (x) x.Balance) >> phao, Nhưng; khi chạy SchemaValidator sau: HibernateException: Loại cột sai trong FnhDb.dbo. Số đếm cho cột Số dư. Tìm thấy: float, dự kiến DOUBLE PRECISION
4) Decimal: Bản đồ (Function (x) x.Balance) .Scale (9) .Precision (2) >> SqlException: Quy mô (9) cho cột 'Số dư' phải nằm trong khoảng từ 0 đến 2.
5,6) Thập phân hoặc đôi: Bản đồ (Hàm (x) x.Balance) .Scale (9) .Precision (2). CustomSqlType ("số") >> số (18,0)
7,8) Thập phân hoặc đôi: Bản đồ (Hàm (x) x.Balance) .Cố (9) .Precision (2) .CustomSqlType ("thập phân") >> Thập phân (18,0)
EDIT: tôi bao gồm mã và hbm.xml (xuất khẩu) đối với trường hợp (4) ở đây:
Public Class AccountMap
Inherits ClassMap(Of Account)
Public Sub New()
MyBase.New()
Id(Function(x) x.Id).GeneratedBy.Identity()
Map(Function(x) x.Balance).Scale(9).Precision(2)
Map(Function(x) x.Deposits)
Map(Function(x) x.WithDrawals)
End Sub
End Class
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="false">
<class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="RoboTrader.Account, RoboTrader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Account`">
<id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="identity" />
</id>
<property name="Balance" type="System.Decimal, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Balance" precision="2" scale="9" />
</property>
<property name="Deposits" type="System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Deposits" />
</property>
<property name="WithDrawals" type="System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="WithDrawals" />
</property>
</class>
</hibernate-mapping>
EDIT2:
Btw, đây không phải là số VB. Tôi có cùng một vấn đề trong dự án C#.Có thể là cấu hình MsSql2008 không tương thích với Sql Express 2008 R2?
EDIT3:
Option Strict On
Imports System.Collections.Generic Imports System.Text Hệ thống nhập khẩu
Public Class Account
Public Sub New()
MyBase.New()
End Sub
Private _Id As Integer
Private _Balance As Double
Private _Deposits As Integer
Private _WithDrawals As Integer
Public Overridable Property Id() As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
Public Overridable Property Balance() As Double
Get
Return _Balance
End Get
Set(ByVal value As Double)
_Balance = value
End Set
End Property
Public Overridable Property Deposits() As Integer
Get
Return _Deposits
End Get
Set(ByVal value As Integer)
_Deposits = value
End Set
End Property
Public Overridable Property WithDrawals() As Integer
Get
Return _WithDrawals
End Get
Set(ByVal value As Integer)
_WithDrawals = value
End Set
End Property
End Class
Ai .. Cảm ơn! Tôi đã kiểm tra điều này chính xác (Def. Của chính xác/quy mô), nhưng phải có đọc nó sai sau đó .. Vâng, đó lá tôi Tôi nghĩ rằng chỉ với một câu hỏi: Làm thế nào đến tôi không thể lập bản đồ một đôi để Decimal/số? Vì nó sẽ luôn tạo một cột (18,0)? – bretddog
Nó phụ thuộc vào cách bạn đã khai báo thuộc tính 'Balance' trong đối tượng của bạn. Bạn có thể đăng tuyên bố của đối tượng POCO không? – Yogesh
Ok, tôi đã thêm cả lớp ở trên. Và bây giờ lập bản đồ như bạn đã nói: Bản đồ (Hàm (x) x.Balance) .CustomSqlType ("thập phân") .Chính xác (9) .Scale (2) – bretddog