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

时间:2008-11-03 22:13:24

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

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

  1. ToyData(Visual Basic类库)

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

  3. 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.
    

    我做错了什么?

1 个答案:

答案 0 :(得分:2)

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


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

检查ToyData项目中的配置文件。将值复制到另一个项目的App.Config文件中(可能尚不存在)。