实体框架+ Sql Anywhere 11 +存储过程

时间:2022-09-13 02:08:45

I have been playing with the EF in the last couple of days. Our applications are based on SQL Anywhere 10 databases, and all our data access are done through stored procedures. Since EF is not supported by SA 10, I am testing EF with SA 11. For this purpose i have create a small database with 2 tables and a couple of stored procedures (based on the nerddinner database from the asp.net mvc samples, see here ) I have created a model from the database, tables and stored procedures and did the necessary function imports. I have a stored procedure with the following signature:

我在过去几天一直在玩EF。我们的应用程序基于SQL Anywhere 10数据库,我们所有的数据访问都是通过存储过程完成的。由于SA不支持EF,我正在使用SA 11测试EF。为此,我创建了一个包含2个表和几个存储过程的小型数据库(基于asp.net mvc示例中的nerddinner数据库,请参阅我已经从数据库,表和存储过程创建了一个模型,并进行了必要的函数导入。我有一个带有以下签名的存储过程:

ALTER PROCEDURE "DBA"."get_dinner"( @dinner_id integer)
BEGIN
select dinner_id, title, event_date, description, hosted_by , contact_phone, address, country, latitude, longitude
from dba.dinners d
where d.dinner_id = @dinner_id
END

And the resulting function import code looks like this:

结果函数导入代码如下所示:

public global::System.Data.Objects.ObjectResult<dinner> get_dinner(global::System.Data.Objects.ObjectParameter dinner_id)
{
    return base.ExecuteFunction<dinner>("get_dinner", dinner_id);
}

And that's the problem. Ideally, the code generated should accept an int parameter, instead of global::System.Data.Objects.ObjectParameter dinner_id As far as I see, the edmx file has all the data it needs to interpret the parameter types correctly:

这就是问题所在。理想情况下,生成的代码应该接受一个int参数,而不是global :: System.Data.Objects.ObjectParameter dinner_id据我所知,edmx文件具有正确解释参数类型所需的所有数据:

<Function Name="get_dinner" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="DBA">
  <Parameter Name="dinner_id" Type="int" Mode="InOut" />
</Function>

Am I missing something here? What else is needed in order to have a function import with the proper parameter type? Is this something you can correct by tweaking the edmx file, or is it a problem of the SA11 EF support implementation.

我在这里错过了什么吗?为了使用适当的参数类型导入函数还需要什么?这是通过调整edmx文件可以纠正的问题,还是SA11 EF支持实现的问题。

Hope someone can give me some further clues.

希望有人能给我一些进一步的线索。

1 个解决方案

#1


This is a known problem with InOut parameters and code gen for Function Imports.

这是InOut参数和函数导入的代码gen的已知问题。

We have been talking about making InOut parameters produce code like this:

我们一直在讨论使InOut参数产生如下代码:

public ObjectResults<dinner> get_dinner(ref int dinner_id);

Rather than what you have.

而不是你拥有的。

One thing to try is converting from an 'InOut' to an 'In' parameter. Code gen should then produce something like this:

要尝试的一件事是从'InOut'转换为'In'参数。 Code gen应该产生这样的东西:

public ObjectResults<dinner> get_dinner(int dinner_id);

The real question though is does it work if you call it?

真正的问题是,如果你打电话,它是否有效?

Hope this background helps

希望这背景有所帮助

Cheers

Alex

#1


This is a known problem with InOut parameters and code gen for Function Imports.

这是InOut参数和函数导入的代码gen的已知问题。

We have been talking about making InOut parameters produce code like this:

我们一直在讨论使InOut参数产生如下代码:

public ObjectResults<dinner> get_dinner(ref int dinner_id);

Rather than what you have.

而不是你拥有的。

One thing to try is converting from an 'InOut' to an 'In' parameter. Code gen should then produce something like this:

要尝试的一件事是从'InOut'转换为'In'参数。 Code gen应该产生这样的东西:

public ObjectResults<dinner> get_dinner(int dinner_id);

The real question though is does it work if you call it?

真正的问题是,如果你打电话,它是否有效?

Hope this background helps

希望这背景有所帮助

Cheers

Alex