是否实体框架code首先支持存储过程? [英] Does Entity Framework Code First support stored procedures?

查看:154
本文介绍了是否实体框架code首先支持存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过EF code第几presentations并没有看到EFCF是如何使用存储过程。

I've watched several presentations of EF Code First and haven't seen how EFCF works with stored procedures.

我怎样才能宣布将使用一些SP的方法?我可以通过一个实体,没有手动映射实体属性用上参数调用SP的方法?

How can I declare a method that will use some sp? Can I pass an entity to a method that calls sp without manually mapping entity properties to sp parameters?

另外,如果我改变我的模式会发生什么?难道将我的SP,而从模型重建表?又是怎么回事触发器?

Also, what happens if I change my model? Would it drop my sp while recreating table from model? And what about triggers?

如果这些东西不被支持,还有支持他们在未来有什么打算?

If these things are not supported, are there any plans to support them in future?

推荐答案

编辑:我的EF4.1(下)原来的答复是已经过时。请参阅从下面的答案迭戈维加(谁在EF团队在微软工作)!

My original answer for EF4.1 (below) is now out of date. Please see the answer below from Diego Vega (who works on the EF team at Microsoft)!

@gsharp和肖恩麦克莱恩:你在哪里得到这个信息?难道你仍然可以访问底层的ObjectContext?

@gsharp and Shawn Mclean: Where are you getting this information? Don't you still have access to the underlying ObjectContext?

IEnumerable<Customer> customers = 
    ((IObjectContextAdapter)this)
    .ObjectContext.ExecuteStoreQuery<Customer>("select * from customers");

替换选择语句和存储过程,而且你去那里。

Replace the "select" statement with a stored proc, and there you go.

至于您的其他问题:是的,很不幸你S.P.的将得到重挫。您可能需要添加CREATE PROCEDURE语句在code。

As for your other question: Yes, unfortunately your s.p.'s will get clobbered. You may need to add the "CREATE PROCEDURE" statements in your code.

有关EF 4.2:

var customers = context.Database.SqlQuery<Customer>("select * from customers")

这篇关于是否实体框架code首先支持存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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