2017年2月24日 星期五

【Entity Framework】Using WHERE IN Clause in Stored Procedure by Entity Framework

這題的問題在 EF ObjectContext 的 YourDbEntities 幫你匯進來的方法參數部分是根據宣告內容哈死的,比方說
  1. Create Proc usp_SelectSomething
  2. @Column1 int,
  3. @Column2 varchar(255)
  4. As
  5. Select * From Table
  6. Where Column1 = @Column1 AND Column2 = @Column2
  7. Go
這樣的話在C# EF 取就會是
  1. public ObjectResult sp_SelectSomething(global::System.Int32 column1, global::System.String column2)
  2. {
  3. ...
  4. }
  5. _MyDbEntitie.usp_SelectSomething(column1, column2);
但是這樣就沒辦法應對 WHERE col IN(...) 的應用,因為無法動態產生不定數量的參數。

2017年2月23日 星期四

【C#】PredicateBuilder usage tip

動態串接 AND, OR 條件應該算是非常常見的需求,在 Linq 段我們常會用 PredicateBuilder 這個擴充來達成,但這個擴充使用上我覺得不是那麼直觀,這篇主要只是要簡單紀錄下
  1. var predicateA = PredicateBuilder.False<YourClass>();
  2. var predicateB = PredicateBuilder.True<YourClass>();
的差異

【C#】Exception when trying Where a PredicateBuilder predicate

Cannot convert expression type 'System.Linq.Expressions.Expression>' to return type 'System.Func'

無法從 'System.Linq.Expressions.Expression>' 轉換為 'System.Func'

2017年2月16日 星期四

【Dapper】'System.Data.SqlClient.SqlConnection' does not contain a definition for 'Query'

剛 Nuget Dapper 然後貼了個範例就立碼噴
'System.Data.SqlClient.SqlConnection' 不包含 'Query' 的定義,也找不到擴充方法 'Query' 來接受類型 'System.Data.SqlClient.SqlConnection' 的第一個引數 (您是否遺漏 using 指示詞或組件參考?)

'System.Data.SqlClient.SqlConnection' does not contain a definition for 'Query' and no extension method 'Query' accepting a first argument of type 'System.Data.SqlClient.SqlConnection' could be found (are you missing a using directive or an assembly reference?)