如何在Visual Basic中使用LINQ to Entities? [英] How do I use LINQ to Entities in Visual Basic?

查看:105
本文介绍了如何在Visual Basic中使用LINQ to Entities?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. ToyData(Visual Basic Class Library)

    >

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


ToyData项目包含一个由玩具数据库生成的ADO.NET实体数据模型Toy.edmx 。



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

 
1导入ToyData
2
3类Window1
4
5 Private Sub Window1_Loaded(_
6 ByVal sender As System.Object,_
7 ByVal e As System.Windows.RoutedEventArgs)_
8处理MyBase。加载
9
10 Dim dc作为新的ToyEntities
11 Label1.Content =(从c作为客户端在dc.ClientSet _
12选择c).First
13
14 End Sub
15
16结束类

它将抛出此运行时异常自动生成

 
配置中找不到指定的命名连接,
不适用于EntityClient提供者,或无效。

我做错了什么?

解决方案

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






如果您右键点击新玩具实用程序,然后进行定义,并继续钻取...您将获得一些自动生成的代码,从中获取连接字符串一个配置文件。



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


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?

解决方案

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.

这篇关于如何在Visual Basic中使用LINQ to Entities?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆