.net - 如何在 Visual Basic 中使用 LINQ to Entities?

标签 .net vb.net linq entity-framework linq-to-entities

我创建了一个包含两个项目的 .NET 解决方案:

  1. ToyData(Visual Basic 类库)

  2. ToyOne(Visual Basic WPF 应用程序)

ToyData 项目包含 Toy.edmx,这是一个从名为 Toy 的数据库生成的 ADO.NET 实体数据模型。

ToyOne 项目包含此 Window1.xaml.vb 文件:

1   Imports ToyData
2   
3   Class Window1
4   
5       Private Sub Window1_Loaded( _
6       ByVal sender As System.Object, _
7       ByVal e As System.Windows.RoutedEventArgs) _
8       Handles MyBase.Loaded
9   
10          Dim dc As New ToyEntities
11          Label1.Content = (From c As Client In dc.ClientSet _
12                            Select c).First
13  
14      End Sub
15  
16  End Class

它在自动生成的 Toy.Designer.vb 文件中抛出这个运行时异常:

The specified named connection is either not found in the configuration,  
not intended to be used with the EntityClient provider, or not valid.

我做错了什么?

最佳答案

我之前在服务项目和测试项目(使用服务中定义的数据对象)之间看到过这个问题。


如果您右键单击“new ToyEntities”并转到定义,并继续深入...您将看到一些自动生成的代码,这些代码从配置文件中获取连接字符串.

检查 ToyData 项目的配置文件。将值复制到其他项目的 App.Config 文件(它可能尚不存在)。

关于.net - 如何在 Visual Basic 中使用 LINQ to Entities?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/260179/

相关文章:

c# - 扩展原始类型

VB.NET:代码不检查面板中是否存在控件

vb.net - 将 Nullable 属性默认值设置为 Nothing 无法正常工作

c# - LINQ to SQL 实体列名称属性被 guid 主键忽略

c# - 如何在 Linq 中获得左外连接?

c# - 让 FluentValidation 调用具有多个参数的函数

c# - 单步执行和跨过时函数的行为不同

c# - 如何检查证书是否是自签名的?

c# - 尝试写入空十进制值时出现 Filehelpers NullReferenceException

linq - Sitefinity 4 带有 LINQ to SQL?