1
votes

I'm trying to make my call to the server with BreezeJS but can't get it to work. It says tblMovie is not recognized. I can't find the problem :S

When I want to add a new movie it says so.

show.js

self.viewAddMovieModal = function () {
        self.app.showModal(new self.addmovie()).then(function (result) {
            if (result != undefined) {
                var movie = dataservice.createMovie({
                    Title: result[0].title,
                    Director: result[0].director
                });
                if (movie.entityAspect.validateEntity()) {
                    self.movies.push(new movie(result[0].title, result[0].director));
                    dataservice.saveChanges();
                } else {
                    alert("Error");
                }
            }
        });
    };

My dataservice.js layer

/// <reference path="../../Scripts/breeze.debug.js"/>

define(["require"], function (require) {

    var Dataservice = (function () {
        function Dataservice(service) {
            this.serviceName = '';
            this._isSaving = false;
            this.serviceName = service;
            this.Manager = new breeze.EntityManager(this.serviceName);
            this.EntityQuery = new breeze.EntityQuery();
        }
        Dataservice.prototype.getAllMovies = function () {
            this.EntityQuery = breeze.EntityQuery.from("AllMovies");
            return this.Manager.executeQuery(this.EntityQuery);
        };

        Dataservice.prototype.createMovie = function (initialValues) {
            return this.Manager.createEntity('tblMovies', initialValues); //THis is where it goes wrong :(
        };

        Dataservice.prototype.saveChanges = function (suppressLogIfNothingToSave) {
            if (this.Manager.hasChanges()) {
                if (this._isSaving) {
                    setTimeout(this.saveChanges, 50);
                    return;
                }
                this.Manager.saveChanges().then(this.saveSucceeded).fail(this.saveFailed).fin(this.saveFinished);
            } else if (!suppressLogIfNothingToSave) {
            }
        };
        Dataservice.prototype.saveSucceeded = function (saveResult) {
            this._isSaving = false;
        };
        Dataservice.prototype.saveFailed = function (error) {
        };
        Dataservice.prototype.saveFinished = function () {
            this._isSaving = false;
        };
        return Dataservice;
    })();
    return Dataservice;
})

I do have a model tblMovie

using System;
using System.ComponentModel.DataAnnotations;


namespace DurandalMovieApp.Models
{
    public class tblMovie
    {
        [Key]
        public int MovieID { get; set; }
        public string Title { get; set; }
        public string Director { get; set; }
    }
}

Hope someone can help!

1

1 Answers

0
votes

I think that the problem is that your entity is: tblMovie, not tblMovies.

Try replacing:

return this.Manager.createEntity('tblMovies', initialValues);

With:

return this.Manager.createEntity('tblMovie', initialValues);