简体   繁体   English

使用实体框架将记录插入mysql db

[英]Insert record into mysql db with Entity Framework

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. 问题是它将在mysql表中插入一条新记录,我已经完成了mysql db的映射,并且已经完成了返回数据的测试,并且一切正常。 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. 现在,我从一个文件中读取内容,其中写入了查询,然后让我重新运行它们,并根据写入该文件的单个查询的最终结果返回true或false的结果。 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: txt文件如下:

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: 如果您想通过EF执行mysql查询,这是我知道的方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM