How do I use LINQ to Entities in Visual Basic?

别说谁变了你拦得住时间么 提交于 2019-12-12 14:11:37

问题


I've created a .NET solution with two projects:

  1. ToyData (Visual Basic Class Library)

  2. ToyOne (Visual Basic WPF Application)

The ToyData project contains Toy.edmx, an ADO.NET Entity Data Model generated from a database called Toy.

The ToyOne project contains this Window1.xaml.vb file:

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

It throws this run-time exception in the auto-generated Toy.Designer.vb file:

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

What am I doing wrong?


回答1:


I've seen this issue before between a service project and a test project (that uses the data objects defined in the service).


If you right click on "new ToyEntities" and go to definition, and keep drilling in... you'll get to some auto-generated code that fetches a connection string from a config file.

Check the ToyData project for a config file. Copy the values into an App.Config file (it may not exist yet) for the other project.



来源:https://stackoverflow.com/questions/260179/how-do-i-use-linq-to-entities-in-visual-basic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!