Last active
December 27, 2015 13:09
-
-
Save kiyokura/7331538 to your computer and use it in GitHub Desktop.
NETのboolをOracleのNUMBERのカラムにマッピングしたい(オブジェクトからパラメータにマッピングの場合)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SomeMethod(Hoge filler) | |
{ | |
using(var cn = new Oracle.DataAccess.Clinet.OracleConnection("接続文字列")){ | |
cn.Open(); | |
// -- NG NG NG NG NG NG -- | |
// NUMBER型のカラムis_fooに与えるパラメータIsFooをboolで与えると例外 | |
var r1 = cn.Query("SELECT * FROM Hoge WHERE is_foo = :IsFoo " , filler ); | |
// -- NG NG NG NG NG NG -- | |
// パラメータとして与える場合は暗黙のbool->NUMBER変換を期待しない。 | |
// 自分で型を変換しなおして渡す | |
var param = new { IsFoo = fillter.IsFoo ? -1 : 0 }; | |
var r2 = cn.Query("SELECT * FROM Hoge WHERE is_foo = :IsFoo " , param ); | |
} | |
} | |
class Hoge{ | |
public bool IsFoo { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment