【发布时间】:2013-12-02 14:50:08
【问题描述】:
我想使用 Effort 运行测试,为此我需要指定一个连接字符串,该连接字符串还包含对 .csdl,.ssdl 和 .msl 文件的引用。 (非工作)连接字符串现在看起来像这样:
<add name="SQLAzureConnection" connectionString=
"metadata=res://*/Model.projectContext.csdl|
res://*/Model.projectContext.ssdl|res://*/Model.projectContext.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=(LocalDb)\v11.0;Initial Catalog=Database_Nieuw;Integrated Security=false;MultipleActiveResultSets=False""
providerName="System.Data.EntityClient" />
Model.projectContext 部分是错误的,但我不知道应该是什么。
当我使用此字符串时,我在使用此连接字符串与 Effort 建立模拟数据库连接的测试中收到以下错误。
Test: failed
Result Message: Initialization method
project.Tests.Controllers.ShoppingCartTest.Initialize threw exception.
System.InvalidOperationException: System.InvalidOperationException: Resource res://*
/Model.seashell_brawl_corveeContext.csdl not found..
我不知道在哪里可以找到这个.csdl 文件,我只知道它是必要的。我无法从我的.emdx 文件中创建它们,因为我有一个代码优先数据库,并且在设计器中右键单击不会为Update database from model 提供选项,因为another question 提供了解决方案。我还设置了Metadata Artifact Processing" option to "Embed in Output Assembly。
有谁知道我在哪里可以找到这些文件以及如何正确引用它们?
/编辑:
好的,现在我很清楚这些文件在代码优先项目中不存在。通过在 cmets 下面使用 user20... 的提示,连接字符串现在似乎可以工作了。一个新问题如下:
`Test Outcome: Failed error 0040: The Type date is not qualified with a namespace or
alias. Only primitive types can be used without qualification.`
很奇怪,因为我到处都使用[DataType(DataType.DateTime)]。有谁知道如何解决这个问题?
【问题讨论】:
-
使用 Code First 时,您没有 .csdl、.ssdl 和 .msl。连接字符串也不同。基本上,正确的连接字符串就是您当前连接字符串中所描述的“提供者连接字符串”。
-
好的,这解释了很多!所以我必须使用提供者连接字符串。我会尝试并报告回来。 /Edit 好的,我改变了它。 -> 现在它说“数据源”关键字不受支持。
-
@user3038092 关于
'Data source is not supported'错误,我应该如何引用连接字符串?甚至可能吗?请注意,此连接字符串在我的测试项目中。不在实际项目中,字符串确实有效。 -
将数据源替换为
Server。 stackoverflow.com/questions/19314320/… -
谢谢。现在我得到这个错误:
Test Outcome: Failed error 0040: The Type date is not qualified with a namespace or alias. Only primitive types can be used without qualification.很奇怪,因为我到处都使用[DataType(DataType.DateTime)]。
标签: c# entity-framework connection-string edmx vs-unit-testing-framework