Last active
March 2, 2016 02:02
-
-
Save kiyokura/7331479 to your computer and use it in GitHub Desktop.
OracleのNUMBERのカラムを.NETのboolにマッピングしたい(クエリからオブジェクトにマッピングの場合)
This file contains hidden or 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() | |
{ | |
using(var cn = new Oracle.DataAccess.Clinet.OracleConnection("接続文字列")){ | |
cn.Open(); | |
// -1 を 暗黙でtureとしてbool型にマッピングしてくれる。 | |
var r1 = cn.Query<Hoge>("SELECT -1 as IsFoo FROM DUAL"); | |
// 0 は false | |
var r2 = cn.Query<Hoge>("SELECT 0 as IsFoo FROM DUAL"); | |
// 1 も trueにマッピングする | |
var r3 = cn.Query<Hoge>("SELECT 1 as IsFoo FROM DUAL"); | |
// -- NG NG NG NG NG NG -- | |
// 文字列'-1'は例外 | |
var r4 = cn.Query<Hoge>("SELECT '-1' as IsFoo FROM DUAL"); | |
// -- NG NG NG NG NG NG -- | |
} | |
} | |
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