Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite与LINQ集成到Visual Studio 2010 Express C中_C#_Linq_Sqlite - Fatal编程技术网

C# SQLite与LINQ集成到Visual Studio 2010 Express C中

C# SQLite与LINQ集成到Visual Studio 2010 Express C中,c#,linq,sqlite,C#,Linq,Sqlite,我有一个项目,我最初使用XML作为数据源。我现在正在重构代码以使用SQLite System.Data.SQLite数据源。我已经找到了许多示例来演示如何生成SQL查询,但我更喜欢使用LINQ,因为我更熟悉这种方法 我最初使用LINQpad和LINQ表达式来测试我的LINQ到对象查询。在LINQpad中,我创建了与数据库的连接以及基本模型信息。然后我像这样查询数据库: var site = (from s in siteinfo where s.site_name ==

我有一个项目,我最初使用XML作为数据源。我现在正在重构代码以使用SQLite System.Data.SQLite数据源。我已经找到了许多示例来演示如何生成SQL查询,但我更喜欢使用LINQ,因为我更熟悉这种方法

我最初使用LINQpad和LINQ表达式来测试我的LINQ到对象查询。在LINQpad中,我创建了与数据库的连接以及基本模型信息。然后我像这样查询数据库:

var site = (from s in siteinfo
            where s.site_name == "some name"
            select new Site
            {
              ID = s.id,
              State = s.state,
              City = s.city,
              ...
            }
           );
LINQpad查询识别数据库中的表和列,我能够生成所需的对象

移动到VS 2010 Express时,我添加了System.Data.SQLite和System.Data.SQLite.Linq引用。然后,我在data sources窗格中添加了一个到我的数据库的连接,其中包括app.config文件中的connectionString

问题:应该将此连接作为数据集(我当前的方法)或实体数据模型添加到我的项目中吗?我两个都试过了,但都没有回答下面的问题

当我尝试使用VS从上面重新创建LINQpad查询时,intellisense没有给我选择特定表的选项。相反,我有sitedata.siteinfoDataTable的选项和其他表的类似选项。例如:

var site = (from s in sitedataset.siteinfoDataTable
            where s.site_name == "some name"
            select new Site
            {
              ID = s.id,
              State = s.state,
              City = s.city,
              ...
            }
           );
var states = (from s in sitedataset.siteinfoDataTable
              select s.state).Distinct();
我在sitedataset.siteinfoDataTable引用中遇到以下错误:

找不到源类型“sitedataset.siteinfoDataTable”的查询模式的实现找不到的地方。您是否缺少对“System.Core.dll”的引用或“System.Linq”的using指令

我的项目确实引用了Core.dll,并且我对System.Linq有一个using指令

我还尝试从数据集中查询不同的状态。例如:

var site = (from s in sitedataset.siteinfoDataTable
            where s.site_name == "some name"
            select new Site
            {
              ID = s.id,
              State = s.state,
              City = s.city,
              ...
            }
           );
var states = (from s in sitedataset.siteinfoDataTable
              select s.state).Distinct();
select语句产生以下错误:

无法将lambda表达式转换为类型“string”,因为它不是委托类型

问题:使用VS,如何针对SQLite数据库编写LINQ查询?如何在VS中识别该数据库模式

感谢您的帮助,谢谢