2014-03-25 40 views
0

我是EF新手。 試圖獲取的在線查詢的一些記錄..在Oracle Connection的實體框架中觸發內聯查詢?

我按照 http://geekswithblogs.net/rgupta/archive/2010/06/23/entity-framework-v4-ndash-tips-and-tricks.aspx

有核桃

var lstStatInfo = new List<BISRCNCCYC>(); 
       using (var contextobj = new TADBEntities(_connStr, _scheName)) 
       { 

        string sql = "select * from MYTABLE where MYID = :MYID"; 
        int id = 475; 
        var args = new DbParameter[] { new OracleParameter { ParameterName = "MYID", Value = "475" } }; 
        var students = contextobj.Database.ExecuteSqlCommand(sql, id); 
        return lstStatInfo; 
       } 

甚至試圖 How to pass parameters to the DbContext.Database.ExecuteSqlCommand method?

,但得到錯誤ORA-00936:缺失表達

I我試圖連接oracle而不是SQl ...應該怎樣纔是正確的方法?

+0

問題我同時加入參數越來越...如何添加甲骨文參數EF上下文對象 –

回答

0

改變你的

string sql = "select * from MYTABLE where MYID = {0}"; 

string sql = "select * from MYTABLE where MYID = :MYID"; 
+0

但如何通過oracle的參數花花公子.. –

+0

@RahulChowdhury是否需要像myCommand1.Parameters.Add(「some」,20)' –

+0

這樣的事情它不創建命令對象其創建EF上下文對象..可以請你來一個例子 –