How to use LINQ for objects in Visual Basic?

I created a .NET solution with two projects:

  • ToyData (Visual Basic Class Library)

  • 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
 nine   
 10 Dim dc As New ToyEntities
 11 Label1.Content = (From c As Client In dc.ClientSet _
 12 Select c) .First
 thirteen  
 14 End Sub
 fifteen  
 16 End Class

It throws this exception at runtime in the automatically 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?

+3
linq linq-to-entities entity-framework
source share
1 answer

I saw this problem before between a service project and a test project (which uses data objects defined in the service).


If you right-click on "new ToyEntities" and go to the definition and continue drilling ... you will get some automatically generated code that extracts the connection string from the configuration file.

Check the ToyData project for the configuration file. Copy the values ​​to the App.Config file (it may not exist yet) for another project.

+2
source share

All Articles