无法在Entity Framework中找到存储过程的功能

时间:2009-08-31 18:24:14

标签: entity-framework ado.net

基于数据库myDB,我为所有表生成edmx并编译项目。然后我在myDB中创建存储过程myProc。然后我通过节点存储过程中的“从数据库更新模型”更新模型并添加myProc。没事。然后在myProc上“创建一个函数导入”。没事。然后我编译了项目,很好。

此导入函数的返回类型是标量(字符串),因为myProc返回一个字符串。

然后我想将此函数用于此存储过程,但我可以找到该函数。 如何找出匹配函数并在代码中调用它?

1 个答案:

答案 0 :(得分:1)

在EF 3.5中,只有返回实体的函数才会显示在ObjectServices中。

即。导入将函数拉入概念模型,但不进入代码生成。

我们已经在4.0中解决了这个问题。

与此同时,您可以使用eSQL调用该函数。

即。像这样的东西(伪代码):

EntityConnection connection = ctx.Connection as EntityConnection;
//Open the connection if necessary
connection.Open()
//Create the command
EntityCommand command = new EntityCommand();
command.CommandText = "Function(@p1,@p2");
command.Parameters.Add(...);
command.Parameters.Add(...);
command.Connection = connection;
string s = command.ExecuteScalar().ToString();

希望这有帮助

亚历