开发者

Insert record into mysql db with Entity Framework

开发者 https://www.devze.com 2022-12-27 21:42 出处:网络
the problem is that it will insert a new record in a mysql table, I have already done the mapping of the mysql db and I have already done tests ret开发者_运维百科urning data and everything works.

the problem is that it will insert a new record in a mysql table, I have already done the mapping of the mysql db and I have already done tests ret开发者_运维百科urning data and everything works. Now I read from a file, where there are queries written, I have them run me back and the result of true or false based on the final outcome of single query written to the file. Txt; I did this:

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

but it does not work, I sense that it returns no errors, but neither the result given written in the query. txt file is as follows:

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

anyone can help me?


If you want to execute mysql queries through EF, this is the method I know:

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号