我有一个简单的服务表结构,每个服务都有很多设施.在数据库中,这是一个Service
表和一个Facility
表,其中Facility
表具有对Service表中的行的引用.
在我们的应用程序中,我们有以下LINQ工作:
Services
.Where(s => s.Facilities.Any(f => f.Name == "Sample"))
.GroupBy(s => s.Type)
.Select(g => new { Type = g.Key, Count = g.Count() })
Run Code Online (Sandbox Code Playgroud)
但由于我无法控制的原因,源集在Where
调用之前被投射到非实体对象,这样:
Services
.Select(s => new { Id = s.Id, Type = s.Type, Facilities = s.Facilities })
.Where(s => s.Facilities.Any(f => f.Name == "Sample"))
.GroupBy(s => s.Type)
.Select(g => new { Type = g.Key, Count = g.Count() })
Run Code Online (Sandbox Code Playgroud)
但这引发了以下异常,没有内部异常:
EntityCommandCompilationException: The nested query is not supported. Operation1='GroupBy' Operation2='MultiStreamNest'
Where …
我将以这样一个事实为前提:我真的不知道这是否是实现我正在做的事情的最佳方式,而且我对更好的建议非常开放.
我有一个用户帐户系统使用OAUTH2
它来查找我的数据库中的用户信息并将其保存为变量,$rootScope.userInfo
.它驻留在一个附加到我的应用程序的控制器中body
; 在这里,我认为最高级别的控制器会在其中存在之前加载,但显然不是.
如果我加载了一个试图$rootScope.userInfo
在我mainCtrl
有机会从我的数据库加载它之前尝试访问该对象的视图,它会抛出一个javascript错误并Angular
中断.
作为参考,这里是模板的粗略概念:
<body ng-controller="mainCtrl">
<header>Content</header>
<div class='main-view' ng-controller="userProfile">
<p>{{user.name}}</p>
<p>{{user.email}}</p>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
我加载$rootScope.userInfo
在mainCtrl
这样的:
$http.get('/api/users/' + $cookies.id).
success(function(data) {
$rootScope.userInfo = data.user[0];
console.log("User info is:");
console.log($rootScope.userInfo);
$scope.status = 'ready';
});
Run Code Online (Sandbox Code Playgroud)
然后为了我的userProfile
控制,我做:
function userProfile($scope, $cookies, $http, $routeParams, $rootScope){
if($scope.status == 'ready'){
$scope.user = $rootScope.userInfo;
console.log("Double checking user info, here it is:");
console.log($rootScope.userInfo);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我来自应用程序中不打开的其他页面$rootScope.userInfo
,则API有足够的时间查找并且我的userProfile
页面工作正常.但是,如果进行整页刷新,$rootScope.userInfo
则没有时间加载,我会收到错误. …