OData函数参数类型为double

时间:2018-02-23 08:16:12

标签: c# asp.net asp.net-web-api odata

我创建了一个具有参数var functionUnitConvertDouble = builder.Function("Convert"); functionUnitConvertDouble.Parameter<int>("From"); functionUnitConvertDouble.Parameter<int>("To"); functionUnitConvertDouble.Parameter<double>("Value"); functionUnitConvertDouble.Returns<double[]>(); 的函数:

[HttpGet]
[ODataRoute("ConvertUom(From={uomIdFrom},To={uomIdTo},Value={value})")]
public IHttpActionResult ConvertUom([FromODataUri] int uomIdFrom, 
    [FromODataUri] int uomIdTo, [FromODataUri] double value)
{
    // Some stuff here
}

这是与之相关的方法:

http://localhost:63911/odata/Convert(From=4,To=2,Value=20)

功能没问题,我可以调用此网址,但效果很好。

http://localhost:63911/odata/Convert(From=4,To=2,Value=20.5)

但是,我的最后一个参数是double,当我尝试传递一个double参数时它不起作用(我得到一个错误信息,如&#34;端点不存在&#34;),例如:

mysql>  SELECT @@version;
+-------------------------+
| @@version               |
+-------------------------+
| 5.7.21-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.00 sec)

mysql> show warnings limit 10;
Empty set (0.00 sec)

mysql> explain fru_log_module;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| turn_id    | int(10) unsigned | NO   |     | NULL    |                |
| stime      | int(10) unsigned | NO   |     | NULL    |                |
| event_type | int(10) unsigned | NO   |     | NULL    |                |
| user_id    | int(10) unsigned | NO   |     | NULL    |                |
| message    | text             | NO   |     | NULL    |                |
| count      | int(10) unsigned | NO   |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> SELECT * FROM fru_log_module ORDER BY id DESC LIMIT 2;
+----+---------+------------+------------+---------+-----------------------+-------+
| id | turn_id | stime      | event_type | user_id | message               | count |
+----+---------+------------+------------+---------+-----------------------+-------+
| 32 |     121 | 1518708294 |          3 |       3 | start TurnStatusOrg;  |     1 |
| 31 |     121 | 1518708007 |          3 |       3 | start TurnStatusOrg;  |     1 |
+----+---------+------------+------------+---------+-----------------------+-------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM fru_log_module ORDER BY id DESC LIMIT 1;
Empty set, 29696 warnings (0.00 sec)

mysql> show warnings limit 10;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> use stage
No connection. Trying to reconnect...
Connection id:    7161012
Current database: *** NONE ***

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show warnings limit 10;
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
| Warning | 1287 | 'COM_FIELD_LIST' is deprecated and will be removed in a future release. Please use SHOW COLUMNS FROM statement instead |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.00 sec)

1 个答案:

答案 0 :(得分:0)

由于双精度包含点并且IIS处理点很奇怪(如果它是一个字符串作为参数,则将是相同的),请将其添加到您的web.congfig中。

<system.webServer>
    <!--You might have more stuff here-->

    <modules>
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
    </modules>
</system.webServer>