无法识别微风创建实体类型

Breeze createEntity Type not recognized

本文关键字:实体 类型 创建 微风 识别      更新时间:2023-09-26

我正试图用BreezeJS打电话给服务器,但不能让它工作。它说tblMovie不被识别。我找不到问题:S

当我想添加一个新电影时,它会显示。

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 datasservice .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;
})

我有一个模型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; }
    }
}

希望有人能帮忙!

我认为问题是你的实体是:tblMovie,而不是tblMovies。

试试更换:

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

:

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