I'm working with LINQ for the first time and wanted to get the Mapping to work when I have a money type in SQL, but my domain object property is of type double. How can I express this in the XML file, or in code so that the mapping does not throw the usual "invalid cast" exception?
James Bauer
質問する
1943 次
3 に答える
3
少し話題から外れていますが、これはSQLServerでMoneyタイプを操作するときに誰もが知っておくべきことです。
ダブルは使用せず、小数を使用します。
Doubleは長い浮動小数点数であり、浮動小数点演算を財務計算に使用しないでください。
これを考えてみてください。分数1/3、1 / 3、1 / 3は1に等しいです。ただし、doubleとして表現すると、次のようになります。
.3333 + .3333 + .3333 =.99991ではありません。
1000分の1セントを失うことは些細なことだと思うかもしれませんが、他の誰かと一緒に仕事をしているときはそうではありません。
System.Decimalを使用します。
于 2008-09-06T01:38:30.507 に答える
1
pretty sure Money maps to System.Decimal
于 2008-08-19T14:29:04.490 に答える
1
DBML XML ファイルでは、Column 要素の Expression 属性を次のように設定できます。
<Column Name="Table1.Amount" DbType="smallint" Type="System.Int32"
Expression="CAST(Table1.Amount as int)" />
于 2008-08-19T14:53:49.383 に答える