2010-04-19 114 views
0

問題是它會在mysql表中插入一條新記錄,我已經完成了mysql數據庫的映射,並且我已經完成了測試,返回數據並且一切正常。 現在我從一個文件中讀取,其中有查詢寫入,我讓他們運行回來,並根據寫入文件的單個查詢的最終結果得出真或假的結果。文本; 我這樣做:用實體框架將記錄插入到MySQL數據庫

using (var w = new demotestEntities()) 
( 
    foreach (var l listaqueri) 
    ( 
     var p = we.CreateQuery <category> (l); 
     we.SaveChanges(); 
     result = true; 
    ) 
) 

,但它不工作,我感覺到它返回沒有錯誤,但也給 書面查詢結果。 txt文件如下:

INSERT INTO category (id, name) VALUES (null, 'test2') 

任何人都可以幫助我嗎?

回答

0

如果你想通過執行mysql的EF查詢,這是我所知道的方法:

var context = new demotestEntities(); 
context.Connection.Open(); 
var command = ((EntityConnection) context.Connection).StoreConnection.CreateCommand(); 
command.CommandText = "INSERT INTO category (id, name) VALUES (null, 'test2')"; 
command.ExecuteNonQuery(); 
相關問題