Entity framework 实体框架中的存储过程
我试图在实体框架中使用一个不返回任何内容的存储过程。存储过程纯粹用于日志记录 我添加了一个函数(右键单击->添加->函数导入),该函数仅在返回值设置为其中一个实体时有效。当我将返回类型更改为Int32、Bool或nothing,或实体以外的任何其他值时,只要我点击build按钮,函数(方法)就会消失Entity framework 实体框架中的存储过程,entity-framework,stored-procedures,Entity Framework,Stored Procedures,我试图在实体框架中使用一个不返回任何内容的存储过程。存储过程纯粹用于日志记录 我添加了一个函数(右键单击->添加->函数导入),该函数仅在返回值设置为其中一个实体时有效。当我将返回类型更改为Int32、Bool或nothing,或实体以外的任何其他值时,只要我点击build按钮,函数(方法)就会消失 关于如何对其进行排序,有什么建议吗?目前,您不能这样做-您必须使用模型中定义的一个实体(尽管我认为INT等基本标量类型也可以使用) EF4将于2009年底或2010年初推出,届时情况会好得多 有关这
关于如何对其进行排序,有什么建议吗?目前,您不能这样做-您必须使用模型中定义的一个实体(尽管我认为INT等基本标量类型也可以使用) EF4将于2009年底或2010年初推出,届时情况会好得多 有关这些新功能的一些信息,请参阅以下文章:
Marc这是从enity framework执行存储过程的一种方法:
using (SEntities se = new SEntities())
{
EntityConnection entityConnection = (EntityConnection)se.Connection;
DbConnection storeConnection = entityConnection.StoreConnection;
storeConnection.Open();
DbCommand command = storeConnection.CreateCommand();
command.CommandText = "NameOfStoredProcedure";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("param1", value_of_param1));
command.Parameters.Add(new SqlParameter("param2", value_of_param2));
SqlParameter param3 = new SqlParameter();
pA.SqlDbType = SqlDbType.Bit;
pA.ParameterName = "@param3";
pA.Direction = ParameterDirection.Output;
command.Parameters.Add(param3);
command.ExecuteNonQuery();
returnValue = Convert.ToBoolean(param3.Value);
}
根据EF 4.1,这是可能的。在Ef 4.0之前,这是不可能的。 在ef 4.1中,可以使用以下行调用sp
res = ctx.Database.SqlQuery<MyResultType1>(...your SP call...);
res=ctx.Database.SqlQuery(…您的SP调用…);
有关更多说明,请参阅