我有一个MVC4应用程序,我最近升级到Entity Framework 5,我试图将我们的数据库移动到使用从删除和创建每个运行的开发风格的迁移.
这是我在app启动功能中所做的.
protected void Application_Start()
{
Database.SetInitializer(
new MigrateDatabaseToLatestVersion< MyContext, Configuration >() );
...
}
Run Code Online (Sandbox Code Playgroud)
我Enable-Migrations在我的存储库项目上运行了命令,我认为这将创建一个初始迁移文件,但它创建的唯一文件是Configuration
当我删除数据库时,它首先通过代码按预期创建它,并从配置文件中播种数据库.在配置文件中,我将所有Add()功能都更改为AddOrUpdate()
但是,Configuration每次网站启动时,它都会在我的文件中运行种子功能,并一次又一次地复制所有种子数据.
我想象它会创建一个initial migration文件,因为我读过的博客建议我会将种子数据放在那里,但它没有
任何人都可以解释我应该如何在代码中设置数据库,以便它只播种一次?
虽然这对于使用EF migrate.exe非常有趣,但我已经转而使用roundhouse来运行迁移.我仍然使用EF来基于模型来构建我的迁移,但是我编写了一个小的控制台应用程序来将迁移写入SQL文件.然后我使用roundhouse通过我的rake构建脚本自己执行迁移.还有一些涉及的过程,但它比使用EF在应用程序启动时动态执行迁移要稳定得多.
asp.net-mvc entity-framework ef-code-first asp.net-mvc-4 entity-framework-5
我有两个代码第一个模型,Foo和FooState,其中Foo有一个可选的FooState.
public class Foo
{
[Key]
public int FooId { get; set; }
public FooState FooState { get; set; }
}
public class FooState
{
[Key]
public int FooStateId { get; set; }
[Required]
public int State { get; set; }
[Required]
public Foo Foo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但是当我尝试将外键添加到FooState时,就像这样
public class FooState
{
[Key]
public int FooStateId { get; set; }
[Required]
public int State { get; set; }
[ForeignKey("Foo")]
[Required]
public int FooId
public Foo Foo { …Run Code Online (Sandbox Code Playgroud) 我正在尝试发送一个9MB的.xls文件作为web api控制器方法的响应.用户将单击页面上的按钮,这将通过浏览器触发下载.
这是我到目前为止所得到的,但它不起作用,但它也没有抛出任何例外.
[AcceptVerbs("GET")]
public HttpResponseMessage ExportXls()
{
try
{
byte[] excelData = m_toolsService.ExportToExcelFile();
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new MemoryStream(excelData);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Data.xls"
};
return result;
}
catch (Exception ex)
{
m_logger.ErrorException("Exception exporting as excel file: ", ex);
return Request.CreateResponse(HttpStatusCode.InternalServerError);
}
}
Run Code Online (Sandbox Code Playgroud)
这是通过界面中的按钮单击调用coffeescript/javascript jquery ajax.
$.ajax(
url: route
dataType: 'json'
type: 'GET'
success: successCallback
error: errorCallback
)
Run Code Online (Sandbox Code Playgroud)
现在我想到它也许dataType是错误的,不应该是json ...
我有两个类似的咖啡师课程.在基本视图模型中,我有一个方法,我想在从基本视图模型继承的子窗口中重写.
class exports.BaseViewModel
constructor: () ->
someBaseMethod: =>
console.log "I'm doing the base stuff"
class ChildViewModel extends BaseViewModel
constructor: () ->
someBaseMethod: =>
@doSomethingFirst()
super @someBaseMethod()
Run Code Online (Sandbox Code Playgroud)
这不能正常工作,因为该行super @someBaseMethod()调用自身创建一个无限循环.
有可能实现我想要的吗?
我正在使用CSVHelper读取大量数据
我想知道是否可以读取最后一n列并将它们转换为列表
"Name","LastName","Attribute1","Attribute2","Attribute3"
Run Code Online (Sandbox Code Playgroud)
并将数据塑造成这样的东西
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public IList<string> Attributes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我希望一步到位,我确信我可以有一个中间步骤,我放入一个具有匹配属性属性的对象但是在一个人上做它会很好
我有一些数据"Foo",我想从浏览器传递到服务器,并根据foo中包含的信息检索预测的统计信息.
$.ajax({
type: 'GET',
url: "/api/predictedStats/",
data: "foo=" + ko.toJSON(foo, fooProperties),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(data) {
return _this.viewModel.setPredictedStats(data);
},
error: function(jqXHR, statusText, errorText) {
return _this.viewModel.setErrorValues(jqXHR, errorText);
}
});
Run Code Online (Sandbox Code Playgroud)
我创建了一个预测的统计控制器和获取Foo参数的方法.
public class PredictedStatsController : ApiController
{
public PredictedStats Get(Foo foo)
{
return statsService.GetPredictedStats(foo);
}
}
Run Code Online (Sandbox Code Playgroud)
在Get方法上粘贴断点我看到Foo对象始终为null.webapi跟踪日志记录中没有抛出任何错误,只有以下几行.
WEBAPI: opr[FormatterParameterBinding] opn[ExecuteBindingAsync] msg[Binding parameter 'foo'] status[0]
WEBAPI: opr[JsonMediaTypeFormatter] opn[ReadFromStreamAsync] msg[Type='foo', content-type='application/json; charset=utf-8'] status[0]
WEBAPI: opr[JsonMediaTypeFormatter] opn[ReadFromStreamAsync] msg[Value read='null'] status[0]
Run Code Online (Sandbox Code Playgroud)
我没有问题通过帖子将数据发送到Foo控制器以在服务器上创建Foo对象,所以我可以说json创建的客户端没有任何问题.
在fiddler中查看得到的Get看起来像以下jsondata是对象foo.
GET /api/predictedStats?foo={jsondata} HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
这甚至是可能还是我认为这一切都错了?
谢谢尼尔
编辑:我觉得我几乎得到了以下工作
public PredictedStats Get([FromUri]Foo …Run Code Online (Sandbox Code Playgroud) 我试图通过添加一些selenium功能来扩展xUnit断言方法
namespace MyProject.Web.Specs.PageLibrary.Extensions
{
public static class AssertExtensions
{
public static void ElementPresent(this Assert assert, ...)
{
if (...)
{
throw new AssertException(...);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用它时,我得到了这个编译错误.
using MyProject.Web.Specs.PageLibrary.Extensions;
using Xunit;
...
public void DoSomething()
{
Assert.ElementPresent(...);
}
Run Code Online (Sandbox Code Playgroud)
而错误
Error 5 'Xunit.Assert' does not contain a definition for 'ElementPresent'
Run Code Online (Sandbox Code Playgroud)
有谁知道这是可能的还是我出错的地方?
我有这个配置工作,并正确重定向以下错误
<httpErrors errorMode="Custom"
existingResponse="Replace"
defaultResponseMode="ExecuteURL" >
<remove statusCode="403" />
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error/ApplicationError" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
但是当我添加以下默认路径以尝试添加catch all时
<httpErrors errorMode="Custom"
existingResponse="Replace"
defaultResponseMode="ExecuteURL"
defaultPath="/Error/ApplicationError">
Run Code Online (Sandbox Code Playgroud)
服务器抛出web.config错误
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Module CustomErrorModule
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!!
目前,我有一小组集成测试针对我的web服务器运行,它提出请求并声明对响应应该是什么的一些假设.这些是用Ruby生成的http请求.
我一直在看Gatling压力测试工具,但我想知道它是否也可以用于集成测试.这样,所有端点请求都可以在压力测试和集成测试中重用.
我可能在这里失去了一些东西,因为没有RSpec的BDD但是没有必要两次创建相同的测试.
有没有人有过以这种方式使用加特林的经验?
我正在关注简单的注入器文档站点上的文档.
https://simpleinjector.readthedocs.org/en/latest/diagnostics.html
var container = new Container();
container.RegisterWebApiControllers(config);
container.Verify();
var results = Analyzer.Analyze(container);
results.Should()
.HaveCount(0, String.Join( Environment.NewLine, results.Select(x => x.Description)));
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的测试时,我收到以下错误
Xunit.Sdk.AssertException:
Expected collection to contain 0 item(s) because
MyController is registered as transient, but implements IDisposable.,
but found 1.
Run Code Online (Sandbox Code Playgroud)
我不知道如何设置控制器的范围,因为该方法container.RegisterWebApiControllers(config)是webapi包的一部分,并且没有任何重载.如何根据网络请求设置这些内容?在其他地方,我会这样做,container.Register<IPinger, Pinger>(lifestyle);但似乎我应该使用打包的帮助方法
添加此行以过滤掉不需要的误报
results = results.Where(x =>
!(x.ServiceType.BaseType == typeof (ApiController) &&
x.Description.Contains("IDisposable"))
).ToArray();
Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×2
ajax ×1
asp.net-mvc ×1
assert ×1
coffeescript ×1
csvhelper ×1
excel ×1
gatling ×1
iis-7 ×1
javascript ×1
jquery ×1
ruby ×1
web-config ×1
xls ×1
xunit.net ×1