2009-08-31 53 views
1

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

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

然后我想用这个函数来存储这个存储过程,但是我可以找到这个函数。 如何找出匹配函数并在代码中调用它?

回答

1

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

I.e.导入会将函数拉入概念模型中,但不会导入代码生成中。

我们已经在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(); 

希望这有助于

亚历