用实体框架将记录插入到MySQL数据库
问题描述:
问题是它会在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')
任何人都可以帮助我吗?
答
如果你想通过执行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();