简体   繁体   English

移动Azure服务C#.NET后端补丁未更新

[英]Mobile Azure Service C# .NET Backend PATCH not updating

I've created a simple .NET backend mobile azure service in C#. 我已经在C#中创建了一个简单的.NET后端移动Azure服务。 I have the mobile service up and running (all it's doing currently is working with your normal CRUD on a single table). 我已经启动并运行了移动服务(当前正在做的就是在一张桌子上使用普通的CRUD)。 The problem I'm having is that the PATCH/UPDATE will not do as it says. 我遇到的问题是PATCH / UPDATE无法按照它说的那样进行。 I can do everything else I've tried, SELECT, INSERT, DELETE, but I've been unable to update data. 我可以做其他所有尝试的事情,例如SELECT,INSERT,DELETE,但是我无法更新数据。

When I debug into the block of code that calls UpdateAsync, the patch.GetEntity()..... always has the values NULL or zeroed out or day one datetimes, like it's not passing along the property values of what I'm trying to update. 当我调试调用UpdateAsync的代码块时,patch.GetEntity().....始终具有NULL或清零值或第一天的日期时间,就像它没有传递我尝试的属性值一样更新。 The only value I ever have is the correct id. 我唯一拥有的值是正确的ID。 Below I tried to strip out some of the code I have, I used some of what was in the first few tutorials on the Azure website. 在下面,我尝试剥离一些代码,然后使用Azure网站上前几篇教程中的内容。

I have a Data Object: 我有一个数据对象:

public class AdminLookupDATA: EntityData
{
    public string description { get; set; }
    public int lookuptype { get; set; }
    public int priority { get; set; }
    public bool inactive { get; set; }
    public DateTime createdate { get; set; }
    public DateTime editdate { get; set; }
}

I have a DTO: 我有一个DTO:

public class AdminLookupDTO
{
    public string id { get; set; }
    public string description { get; set; }
    public int lookuptype { get; set; }
    public int priority { get; set; }
    public bool inactive { get; set; }
    public DateTime createdate { get; set; }
    public DateTime editdate { get; set; }
}

I have a Model: 我有一个模特:

public class AdminLookupModel
{
    public string Id { get; set; }
    public string description { get; set; }
    public int lookuptype { get; set; }
    public int priority { get; set; }
    public bool inactive { get; set; }
    public DateTime createdate { get; set; }
    public DateTime editdate { get; set; }
}

My PATCH inside my controller: 我的控制器内部的PATCH:

    public Task<AdminLookupDATA> PatchAdminLookupDATA(string id, Delta<AdminLookupDATA> patch)
    {
         return UpdateAsync(id, patch);
    }

Also, I have the same issue if I try to run the PATCH function directly from the browser in the "try it out" section, so it's something I have configured wrong within the service project itself. 另外,如果我尝试直接从浏览器的“试用”部分中运行PATCH函数,则会遇到相同的问题,因此在服务项目本身中配置了错误。 Any suggestions would be greatly appreciated. 任何建议将不胜感激。

Thanks, Rob 谢谢,罗伯

Your property names must start with a capital letter. 您的财产名称必须以大写字母开头。

Otherwise configure the CamelCasePropertyNamesContractResolver as indicated here: 否则,按如下所示配置CamelCasePropertyNamesContractResolver:

http://odetocode.com/blogs/scott/archive/2013/03/25/asp-net-webapi-tip-3-camelcasing-json.aspx http://odetocode.com/blogs/scott/archive/2013/03/25/asp-net-webapi-tip-3-camelcasing-json.aspx

code snippet 程式码片段

var formatters = GlobalConfiguration.Configuration.Formatters;
var jsonFormatter = formatters.JsonFormatter;
var settings = jsonFormatter.SerializerSettings;
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM