小编Eri*_*118的帖子

接收OData.PageResult <T>时如何避免406?

我有一个返回PageResult的ODataController.

Api示例:

public PageResult<Customer> Get(ODataQueryOptions options) {
// cut some stuff out...

    PageResult<Customer> result = new PageResult<Customer>(
        searchResults as IEnumerable<Customer>,
        Request.GetNextPageLink(),
        Request.GetInlineCount());
    return result;
Run Code Online (Sandbox Code Playgroud)

当我调试它时,似乎很好并且正确构建了一个PageResult类来返回.在网络上..

网络示例

using (var client = new HttpClient()) {
    client.BaseAddress = new Uri(testURL);
    string searchUrl = "api/customer?$top=1&$skip=0";
    client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata=verbose"));
    HttpResponseMessage response = client.GetAsync(searchUrl).Result;
Run Code Online (Sandbox Code Playgroud)

响应是StatusCode 406,其中有一个原因短语说明内容不可接受.如果我定义一个新的MediaTypeWithQualityHeaderValue("application/json"),它也会这样做.

我需要更改什么才能在将控制器传递给视图之前在控制器中成功使用此Api?

asp.net asp.net-mvc odata asp.net-mvc-4

5
推荐指数
1
解决办法
8710
查看次数

什么时候在声明变量/参数时使用 ArrayList 或 LinkedList 而不是 List 是正确的?

假设你有一个类似的类:

public class foo {
    private List<String> fooThings;

    public void doSomething(List<String> things) {
        // Do a bunch of things here
        // Possibly setting fooThings at some point as well
    }
}
Run Code Online (Sandbox Code Playgroud)

声明指定具体类(例如 ArrayList 而不是 List 接口)是否合适?如果有,什么时候?

编辑> 这个问题与何时使用 LinkedList 以及何时使用 ArrayList 无关。这是一个单独的问题,在别处回答。问题是为了清楚起见,何时声明应该是接口(List),何时应该指定一个实现,例如 ArrayList,因为考虑到方法将要做什么或如何利用实例变量,这很重要。

java

5
推荐指数
1
解决办法
1396
查看次数

如何从C#中的存储过程中获取所选值?

在查看存储过程时,逻辑似乎是"做东西",然后是select 1 as add_success.如何add_success在C#中检查该值?

using (SqlConnection connection = new SqlConnection(_connectionString)) {
  using (SqlCommand command = new SqlCommand("<sprocname>", connection)) {
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(<a parameter>); // x10 or so
    connection.Open();
    var result = command.ExecuteNonQuery();
    // result is always -1, despite the sproc doing everything it is supposed to do (modify a few different tables)
Run Code Online (Sandbox Code Playgroud)

存储过程

// Do some stuff including inserts on a few different tables, then
INSERT INTO Table (field1, field2)
VALUES (@Val1, @Val2)

SELECT …
Run Code Online (Sandbox Code Playgroud)

c# sql-server stored-procedures

2
推荐指数
1
解决办法
113
查看次数