Breeze with Angular entityManagerfactory

时间:2017-09-04 03:13:42

标签: javascript angularjs breeze

我正在尝试使用Angular为Breeze创建entityManagerFactory。我使用HotTowel来开始我的项目但是当我尝试获取新的工厂集时,我从breeze.debug.js模块中收到错误。它落入那里因为看起来它希望属性的类型与属性的名称相匹配。我不确定我是否明白这里发生了什么。谁能指出我正确的方向? 在datacontext.js中调用代码:

        function getProjects() {
        return breeze.EntityQuery.from('Projects')
            .using(manager)
            .execute()
            .then(success)
            .catch(fail)
    };

工厂服务:

(function() {
'use strict';

var serviceId = 'entityManagerFactory';
angular.module('app').factory(serviceId, ['breeze', emFactory]);

function emFactory(breeze) {
    // Convert server-side PascalCase to client-side camelCase property names
    breeze.NamingConvention.camelCase.setAsDefault();
    // Do not validate when we attach a newly created entity to an EntityManager.
    // We could also set this per entityManager
    new breeze.ValidationOptions({ validateOnAttach: false }).setAsDefault();

    var serviceRoot = "http://localhost:51362/";
    var serviceName = serviceRoot + 'breeze/ProjectTracking';

    var manager = new breeze.EntityManager(serviceName);
    var factory = {
        newManager: manager,
        serviceName: serviceName
    };

    return factory;        
}

})();

breeze.debug.js中的违规代码:

function processUsing(eq, map, value, propertyName) {
var typeName = value._$typeName || (value.parentEnum && value.parentEnum.name);
var key = typeName && typeName.substr(0, 1).toLowerCase() + typeName.substr(1);
if (propertyName && key != propertyName) {
  throw new Error("Invalid value for property: " + propertyName);
}

的软件包:

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
  <package id="AngularJS.Animate" version="1.2.22" targetFramework="net461" />
  <package id="AngularJS.Core" version="1.2.22" targetFramework="net461" />
  <package id="AngularJS.Route" version="1.2.22" targetFramework="net461" />
  <package id="AngularJS.Sanitize" version="1.2.22" targetFramework="net461" />
  <package id="Antlr" version="3.4.1.9004" targetFramework="net461" />
  <package id="bootstrap" version="3.1.1" targetFramework="net461" />
  <package id="Breeze.Angular" version="1.0.0" targetFramework="net461" />
  <package id="Breeze.Angular.Directives" version="1.3.10" targetFramework="net461" />
  <package id="Breeze.Client" version="1.5.3" targetFramework="net461" />
  <package id="Breeze.Server.ContextProvider" version="1.5.0" targetFramework="net461" />
  <package id="Breeze.Server.WebApi2" version="1.5.0" targetFramework="net461" />
  <package id="EntityFramework" version="6.1.3" targetFramework="net461" />
  <package id="FontAwesome" version="4.1.0" targetFramework="net461" />
  <package id="HotTowel.Angular" version="2.3.3" targetFramework="net461" />
  <package id="HotTowel.Angular.Breeze" version="2.3.3" targetFramework="net461" />
  <package id="jQuery" version="2.1.1" targetFramework="net461" />
  <package id="Knockout.Validation" version="1.0.1" targetFramework="net461" />
  <package id="knockoutjs" version="2.3.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.6" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.2.2" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.5" targetFramework="net461" />
  <package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net461" />
  <package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net461" />
  <package id="Microsoft.Net.Compilers" version="2.1.0" targetFramework="net461" developmentDependency="true" />
  <package id="Microsoft.Owin" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Facebook" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Twitter" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
  <package id="Modernizr" version="2.6.2" targetFramework="net461" />
  <package id="Moment.js" version="2.6.0" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
  <package id="Owin" version="1.0" targetFramework="net461" />
  <package id="Q" version="0.8.12" targetFramework="net461" />
  <package id="Respond" version="1.2.0" targetFramework="net461" />
  <package id="Sammy.js" version="0.7.4" targetFramework="net461" />
  <package id="Spin.js" version="2.0" targetFramework="net461" />
  <package id="System.Spatial" version="5.6.0" targetFramework="net461" />
  <package id="toastr" version="2.0.3" targetFramework="net461" />
  <package id="WebActivator" version="1.0.0.0" targetFramework="net461" />
  <package id="WebGrease" version="1.5.2" targetFramework="net461" />
    </packages>

错误:

Error

1 个答案:

答案 0 :(得分:0)

在您的datacontext服务中,您可以添加以下内容:

var _primePromise;

function prime() {
   if (_primePromise) return _primePromise;
   _primePromise = manager.fetchMetadata()
      .then(extendMetadataStore)
      .catch(function(err) {
         _primePromise = null;
         throw err;
      });
   return _primePromise;
}

function extendMetadataStore() {
   var store = manager.metadataStore;
   var entityTypes = store.getEntityTypes();
   entityTypes.forEach(function(entityType) {
      if (entityType instanceof EntityType) {
         var resourceName = entityType.shortName;
         store.setEntityTypeForResourceName(resourceName, entityType);
      }
   });
}

然后,您只需确保在调用getProjects()之前调用datacontext.prime()。 我在解析路由之前调用了datacontext.prime()。