简体   繁体   English

Query()上的Azure移动服务AutoMapper HttpResponseException

[英]Azure Mobile Services AutoMapper HttpResponseException at Query()

I tried to comple this Tutorial . 我试图完成本教程 The content is just simple Mapping of an object to a DTO . 内容仅仅是对象到DTO简单映射。

I initialized my Mapper at WebConfig.cs 我在WebConfig.cs初始化了我的Mapper

 public static void Register()
    {
        // Use this class to set configuration options for your mobile service
        ConfigOptions options = new ConfigOptions();

        // Use this class to set WebAPI configuration options
        HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

        AutoMapper.Mapper.Initialize(cfg =>
        {
            // Define a map from the database type TodoItem to 
            // client type TodoItemDto. Used when getting data.
            cfg.CreateMap<TodoItem, TodoItemDto>();
            // Define a map from the client type to the database
            // type. Used when inserting and updating data.
            cfg.CreateMap<TodoItemDto, TodoItem>();
        });

        // To display errors in the browser during development, uncomment the following
        // line. Comment it out again when you deploy your service for production use.
        // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

        Database.SetInitializer(new my_Initializer());
    }

I added my DTO-Class as shown in the Tutorial and prepared my Controller 如教程中所示,我添加了我的DTO类,并准备了我的控制器

 public class TodoItemController : TableController<TodoItemDto>
{


    protected override void Initialize(HttpControllerContext controllerContext)
    {
        base.Initialize(controllerContext);
        my_Context context = new my_Context();
        DomainManager = new SimpleMappedEntityDomainManager(context, Request, Services);
    }

    public IQueryable<TodoItemDto> GetAllTodoItems()
    {
            return Query();
    }
    public SingleResult<TodoItemDto> GetTodoItem(string id)
    {
        return Lookup(id);
    }
    public Task<TodoItemDto> PatchTodoItem(string id, Delta<TodoItemDto> patch)
    {
        return UpdateAsync(id, patch);
    }
    public async Task<IHttpActionResult> PostTodoItem(TodoItemDto item)
    {
        TodoItemDto current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }
    public Task DeleteTodoItem(string id)
    {
        return DeleteAsync(id);
    }
}

I went step by step through the tutorial. 我一步一步地完成了本教程。 I really tried to do exactly the same. 我真的尝试做完全一样的事情。 But in the end I allways get an HttpResponseException when I call GetAllTodoItems() . 但是最后,当我调用GetAllTodoItems()时,我总是得到HttpResponseException

//Edit: I get my HttpResponseException when I call GetAllTodoItems() at return Query() . //编辑:当我在return Query()处调用GetAllTodoItems()时,得到了HttpResponseException

I can see the my two TodoItems (that I seeded) in the Context. 我可以在Context中看到我的两个TodoItems(已播种)。 So my Context isn't empty. 所以我的上下文不为空。 My DomainManager is the same as in the tutorial. 我的DomainManager与本教程中的相同。

I dont even map different values. 我什至不映射不同的值。 My models are simmilar as in the first chapter of the tutorial. 我的模型与本教程第一章类似。

public class TodoItem : EntityData
{
    public string Text { get; set; }

    public bool Complete { get; set; }
}

public class TodoItemDto : Microsoft.WindowsAzure.Mobile.Service.EntityData
{
    public string Text { get; set; }
    public bool Complete { get; set; }
}

Mapping looks soo easy and I dont understand what I am doing wrong. 映射看起来太容易了,我不明白我在做什么错。

Man your code looks good. 伙计,您的代码看起来不错。 As i see it maybe the DomainManager have something wrong but cant tell if you dont post it or there is some problems with the EntityFramework( was common for me ). 如我所见,DomainManager可能有问题,但是无法告诉您是否不发布它,或者EntityFramework(对我来说很常见)存在一些问题。

You better provide us with the Error exception from the Stack. 您最好从堆栈中为我们提供Error异常。

Last check your database schema it must be exactly the same as your models including the EntityData properties or if you go Code-First set up your Initializer right. 最后检查您的数据库模式,它必须与包括EntityData属性的模型完全相同,或者如果您进行代码优先设置,请正确设置初始化器。 Use a ClearSchemaIfModelChanges Initializer. 使用ClearSchemaIfModelChanges初始化程序。 Maybe there are some changes since your Seed. 自从您的种子以来,也许有一些变化。

i found out that i got a MissingMethodException in my DomainManager . 我发现我的DomainManagerMissingMethodException I overwrited the Query() of my DomainManager and found it finally. 我覆盖了DomainManagerQuery()并最终找到了它。 Looks like I had some problems with the nugetpackages / versioning. 看起来我在nugetpackages /版本控制方面遇到了一些问题。

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

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