views:

49

answers:

1

Hi, 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 returning 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?

A: 

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