【问题标题】:Where to find .csdl, .ssdl, and .msl files in Entity Framework 4.0 code first?首先在 Entity Framework 4.0 代码中的哪里可以找到 .csdl、.ssdl 和 .msl 文件?
【发布时间】: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=&quot;Data Source=(LocalDb)\v11.0;Initial Catalog=Database_Nieuw;Integrated Security=false;MultipleActiveResultSets=False&quot;"
 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' 错误,我应该如何引用连接字符串?甚至可能吗?请注意,此连接字符串在我的测试项目中。不在实际项目中,字符串确实有效。
  • 将数据源替换为Serverstackoverflow.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


【解决方案1】:

正如user3038092 解释的那样:

使用 Code First 时,您没有 .csdl、.ssdl 和 .msl。这 连接字符串也不同。基本上正确的连接 string 是被描述为“提供者连接字符串”的内容 你当前的连接字符串

解决问题。

【讨论】:

  • 给出问题的链接,而不是用户。
  • @AltafPatel 这是上述问题下的第一条评论。
  • 我现在看不到评论,你能不能标记问题而不是用户?
  • @ransems 就像我说的,这是THIS question 下面的第一条评论。如果评论的内容消失了,我会将其复制到此答案中。我不知道如何链接到评论。
猜你喜欢
  • 1970-01-01
  • 2011-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多