Entity Framework 6新的存储过程功能 [英] Entity Framework 6 new stored procedure functionality

查看:90
本文介绍了Entity Framework 6新的存储过程功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我可以通过EF 6创建存储过程的红色消息,但我现在看到的是一些映射和字段编辑选项 http://msdn.microsoft.com/en-us/data/dn468673



以前不支持存储过程创建,但我不明白究竟是什么最后介绍一下,有人可以告诉我这些变化背后的功能吗?

或者有人可以将我重定向到如何使用EF创建存储过程吗?



干杯。

I think i red news that you are able to create Stored Procedures through EF 6 some time before, but what i see now is some mapping and field editing options http://msdn.microsoft.com/en-us/data/dn468673

Stored procedure creation was not supported before, but i dont understand what exactly they introduced in the end, can someone maybe tell me the functionality behind these changes?
Or can someone redirect me to a How-to create stored procedures with EF?

Cheers.

推荐答案

你这样做这...... [ ^ ]



您无法在EF6中创建所需的任何旧存储过程。您只需告诉它在存储过程中创建标准CRUD操作。
You do it like this...[^]

You cannot create any old stored procedure you want in EF6. You merely tell it to create the standard CRUD operations in stored procedures.


EDM设计器不允许您编写存储过程并将它们带入数据库。这意味着您选择代码优先,模型优先或数据库优先方法无关紧要。您总是必须在数据库中创建存储过程,然后将它们导入EDM。



但是你能做到这一点......



EDM designer doesn’t allow you to write stored procedures and bring them into the database. That means it doesn’t matter whether you opt for the code-first, model-first or database-first approach. You always have to create your stored procedures in the database and later import them into the EDM.

But You Can Do That...

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        DbCommand cmd = Database.Connection.CreateCommand();
        cmd.CommandText = "create stored procedure ....";
        cmd.ExecuteNonQuery();
    }  





和你可以使用的地图





And For Mapping You Can Use

modelBuilder 
  .Entity<EntityName>() 
  .MapToStoredProcedures(s => 
    s.Update(u => u.HasName("UpdateStoreProcedureName")) 
     .Delete(d => d.HasName("deleteStoreProcedureName")) 
     .Insert(i => i.HasName("insertStoreProcedureName"))); 





您还可以阅读本链接


检查此示例应用程序:



初学者实施框架 [ ^ ]
Check this sample application:

Entity Framework for Beginners[^]


这篇关于Entity Framework 6新的存储过程功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆