小编use*_*248的帖子

没有找到路由约定来为模板'〜/ entityset'选择OData路径的操作

我定义了两个Odata动作方法.带参数的那个被调用,而没有参数的另一个没有被调用并抛出错误没有找到路由约定来为模板'〜/ entityset'选择OData路径的动作.

这是我的行动方法的代码

[EnableQuery]
    public IQueryable<User> GetUser()
    {
        return db.Users;
    }

    // GET: odata/User(5)
    [EnableQuery]
    public SingleResult<User> GetUser([FromODataUri] int key)
    {
        return SingleResult.Create(db.Users.Where(user => user.Id == key));
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用的查询如下

http://bureauservice/api/odata/UserOdata - Doesnt work
http://bureauservice/api/odata/UserOdata(1) - works
Run Code Online (Sandbox Code Playgroud)

有人能告诉我为什么第一个链接不起作用.

odata c#-4.0 odata4j asp.net-web-api asp.net-web-api-routing

8
推荐指数
2
解决办法
9986
查看次数

测试Patch odata webapi方法

我需要在我的测试项目的odata控制器中测试以下Patch方法.

[ValidateModel]
        [AcceptVerbs("PATCH", "MERGE")]
        public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<User> patch)
        {
            var user = await db.Users.FindAsync(key);
            if (user == null)
            {
                return NotFound();
            }

            patch.Patch(user);

            Validate(user);

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                db.Entry(user).Property(p => p.UserType).IsModified = false;
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(key))
                {
                    return NotFound();
                }
                throw;
            }

            return Updated(user);
        }
Run Code Online (Sandbox Code Playgroud)

测试项目中的代码如下.有人能告诉我如何将值传递给Delta参数.目前我在line controller.Patch(1,user);收到编译错误.

[TestMethod]
        public void TestPatch()
        {
            // Arrange
            var controller = new UsersController();

            var user = new User();
            user.Id = 1; …
Run Code Online (Sandbox Code Playgroud)

c# odata asp.net-web-api asp.net-web-api2

3
推荐指数
1
解决办法
1897
查看次数

检查数组是空还是空

我需要验证我的字符串数组是空还是空.以下是我的代码.两者都不起作用.虽然数组未使用任何值进行初始化,但它显示为包含值.有人可以帮忙吗?

string abc[] = new string[3];

first code 

if(abc != null)
{

}

second code 

if(IsNullOrEmpty(abc))
{

}

public static bool IsNullOrEmpty<T>(T[] array)
{
    return array == null || array.Length == 0;
}
Run Code Online (Sandbox Code Playgroud)

c#

-6
推荐指数
1
解决办法
1万
查看次数