在LINQ中执行SQL时返回id字段
我正在尝试使用 LINQ 执行 SQL 插入查询并返回 ID 字段。我的代码不起作用,有人可以告诉我我的语法是否错误吗?
string query = "insert into EnvironmentalReportDepts ";
query += "(fkDeptID, OrderNumber, fkEnvironmentalReportID) ";
query += "values(" + tmpDeptReport.fkDeptID + ", " + tmpDeptReport.OrderNumber + ", " + tmpDeptReport.EnvironmentalReport.EnvironmentalReportID + ") ";
query += "select scope_identity()";
var newDeptID = _database.ExecuteQuery<int>(query).ToList()[0];
I'm trying to execute an SQL insert query using LINQ and returning the ID field. My code does not work, can anybody tell me if my syntax is wrong?
string query = "insert into EnvironmentalReportDepts ";
query += "(fkDeptID, OrderNumber, fkEnvironmentalReportID) ";
query += "values(" + tmpDeptReport.fkDeptID + ", " + tmpDeptReport.OrderNumber + ", " + tmpDeptReport.EnvironmentalReport.EnvironmentalReportID + ") ";
query += "select scope_identity()";
var newDeptID = _database.ExecuteQuery<int>(query).ToList()[0];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改
为
另外,您可能必须使用
Try changing
to
Also, you may have to use
将查询更改为:
change query to: