调用存储过程或运行sql查询?

时间:2022-03-15 10:05:52

Is it possible yet to execute a stored procedure or execute a piece of SQL in EF7?

是否可能在EF7中执行存储过程或执行SQL片段?

To do this in earlier EF versions we have a variety of options such as those detailed on MSDN here

为了在早期的EF版本中实现这一点,我们有各种各样的选项,比如这里详细介绍的MSDN

If not is there a plan to allow this through one of the Extension namespaces (eg EntityFramework.Relational or EntityFramework.SqlServer).

如果没有,则计划通过一个扩展名称空间(例如EntityFramework)来允许它。关系或EntityFramework.SqlServer)。

At the moment I'm making this call via straight Ado.Net, however that has the disadvantage that it isn't (currently) supported by the dnxcore50 framework.

目前我正在通过一个简单的电话。然而,它的缺点是它(目前)没有dnxcore50框架支持。

2 个解决方案

#1


2  

If it returns entities, use the .FromSql() extension method on DbSet. You can even continue composing LINQ on top of it.

如果它返回实体,请在DbSet上使用. fromsql()扩展方法。你甚至可以在上面继续写LINQ。

var customers = db.Customers
    .FromSql("SELECT * FROM Customer")
    .Where(c => c.Name.StartsWith("A"));

#2


2  

Stored Procedures has not yet implemented in Entity Framework 7,you can track the development here.

存储过程还没有在实体框架7中实现,您可以在这里跟踪开发。

Thanks

谢谢

#1


2  

If it returns entities, use the .FromSql() extension method on DbSet. You can even continue composing LINQ on top of it.

如果它返回实体,请在DbSet上使用. fromsql()扩展方法。你甚至可以在上面继续写LINQ。

var customers = db.Customers
    .FromSql("SELECT * FROM Customer")
    .Where(c => c.Name.StartsWith("A"));

#2


2  

Stored Procedures has not yet implemented in Entity Framework 7,you can track the development here.

存储过程还没有在实体框架7中实现,您可以在这里跟踪开发。

Thanks

谢谢