也许我误解的缓存是DbContext和DbSet做,但我的印象是,有一些高速缓存,将继续下去.当我运行以下代码时,我看到了我不会期望的行为:
var ctx = CreateAContext();
var sampleEntityId = ctx.SampleEntities.Select(i => i.Id)
.Single(i => i == 3); //Calls DB as expected
var cachedEntityId = ctx.SampleEntities.Select(i => i.Id)
.Single(i => i == 3); //Calls DB unexpectedly
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?我认为你得到的部分原因DbSet是它首先检查本地缓存,以便在查询数据库之前查看该对象是否存在.我在这里缺少某种配置选项吗?
我在使用MVC的IIS 8.x上遇到了Angular JS的问题.我的虚拟目录应用程序索引页是这样的:
https://myapp.xyz/VirtualDirectory/
Run Code Online (Sandbox Code Playgroud)
该页面加载角度应用程序.我的角度路线设置为:
$routeProvider
.when('/', {
templateUrl: 'Content/Partials/Home/Index.html'
})
.when('/Error', {
templateUrl: 'Content/Partials/Shared/Error.html'
})
.otherwise({
redirectTo: '/Error'
});
Run Code Online (Sandbox Code Playgroud)
所以,如果我访问第一个链接,我的URL看起来像:
https://myapp.xyz/VirtualDirectory/#/
Run Code Online (Sandbox Code Playgroud)
这完美地工作,并解决了我的偏好.Angular请求部分包含虚拟目录,因此我看到一个HTTP请求:
https://myapp.xyz/VirtualDirectory/Content/Partials/Home/Index.html
Run Code Online (Sandbox Code Playgroud)
但是,如果我在没有尾部斜杠的情况下访问:
https://myapp.xyz/VirtualDirectory
Run Code Online (Sandbox Code Playgroud)
Angular航线:
https://myapp.xyz/VirtualDirectory#/
Run Code Online (Sandbox Code Playgroud)
一旦发生这种情况,我的路线都不起作用(他们不尊重虚拟目录).他们路由为:
https://myapp.xyz/Content/Partials/Home/Index.html
Run Code Online (Sandbox Code Playgroud)
这会破坏我的指令中定义的所有路由和模板.有关如何解决此问题的任何建议?
我是一个单元测试控制器,我想测试一个事件处理程序.说我的控制器看起来像:
myModule.controller('MasterController', ['$scope', function($scope){
$scope.$on('$locationChangeSuccess', function() {
$scope.success = true;
});
}]);
Run Code Online (Sandbox Code Playgroud)
我会在我的Jasmine测试中播放吗?我会发射它吗?有接受的标准吗?
假设我按如下方式定义工厂:
angular.module('myServices').factory('TestService', ['Restangular',
function(restangular){
return restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('api');
RestangularConfigurer.setRestangularFields({ id: 'Id'});
};
}).all('Job');
}]);
Run Code Online (Sandbox Code Playgroud)
我希望能够编写单元测试来确认我baseUrl和该id字段已正确设置.这可能吗?我知道我可以查看.route我的服务上的属性路线,但不包括baseUrl.
我有一个习惯ActionFilterAttribute.为了这个问题,让我们假设它如下:
public class CustomActionFilterAttribute : ActionFilterAttribute {
public bool success { get; private set };
public override void OnActionExecuting(HttpActionContext actionContext) {
//Do something and set success
success = DoSomething(actionContext);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我的控制器用CustomActionFilter.我正在寻找的是一种方式(在我的控制器方法中)做类似的事情:
[CustomActionFilter]
public class MyController : ApiController {
public ActionResult MyAction() {
//How do I get the 'success' from my attribute?
}
}
Run Code Online (Sandbox Code Playgroud)
如果有更可接受的方式,请告诉我.
我有一个带有.NET MVC/WebAPI后端的AngularJS应用程序.我有一个MVC操作,提供我的主要HTML页面加载我的AngularJS应用程序.此MVC操作从Web.config以及数据库加载多个应用程序设置,并将它们作为模型返回到视图.我正在寻找一种在我的AngularJS 方法中将这些MVC Model值设置为$provide.constant值的好.config方法.
MVC控制器方法:
public ActionResult Index() {
var model = new IndexViewModel {
Uri1 = GetUri1(),
Uri2 = GetUri2()
//...etc
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
我的MVC _Layout.cshtml:
@model IndexViewModel
<!doctype html>
<html data-ng-app='myApp'>
<head>
@Styles.Render("~/content/css")
<script type='text/javascript'>
@if (Model != null) //May be null on error page
{
<text>
var modelExists = true;
var uri1 = '@Model.Uri1';
var uri2 = '@Model.Uri2';
</text>
}
else
{
<text>
var modelExists = false;
</text>
}
</script>
</head> …Run Code Online (Sandbox Code Playgroud) 我不太确定如何表达这个问题,但场景如下:
说我有以下课程:
public class SampleClass
{
public int Number { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我知道你可以null合并包含类:
SampleClass newSampleClass = possibleNullSampleClass ?? notNullSampleClass;
Run Code Online (Sandbox Code Playgroud)
有没有办法在属性上执行一种null合并,所以我不必这样做:
int? num = sampleClass != null ? new int?(sampleClass.Number) : 5;
Run Code Online (Sandbox Code Playgroud)
看起来像???运算符之类的东西执行此检查是非常有用的,所以我可以这样做:
int? num = sampleClass.Number ??? 5;
Run Code Online (Sandbox Code Playgroud)
在C#中有可能是这样的吗?
我希望我可以使用这种模式:
var task = Task.Run(() => Agent.GetUserType(Instance));
await task;
string information = task.GetExceptionOrStatus(); // extension method
Run Code Online (Sandbox Code Playgroud)
当我的sql服务器没有启动时 - 就像一个测试用例 - 我看到WCF服务抛出的异常没有被任务正常处理,我得到:
Microsoft中出现了类型'System.ServiceModel.FaultException'的异常. Threading.Tasks.dll但未在用户代码中处理.
我的印象是我的代码能够从任务对象中提取错误.
我该怎么做得更好?
说我有以下方法:
public List<List<int>> DoSomething () {
List<List<int>> result;
//Do some things
return result; //Would like to breakpoint here
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用条件断点,例如:
result.Any(i => i.Any(j => j < 0))
Run Code Online (Sandbox Code Playgroud)
我收到一条错误,说你不能在条件断点中使用lambda表达式.这是为什么?
我有Endpoint一个Handle方法.我想在之前和之后立即采取措施Handle.通过改变,我之前能够完成这个步骤LogCommandEntryBehavior : Behavior<IIncomingLogicalMessageContext>.紧接着需要实施什么Handle?
c# ×6
angularjs ×4
asp.net-mvc ×2
async-await ×1
caching ×1
debugging ×1
exception ×1
iis ×1
jasmine ×1
lambda ×1
nservicebus ×1
nservicebus6 ×1
restangular ×1
syntax ×1
unit-testing ×1