C# 你如何在 Sqlite 中使用 LINQ

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/319210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:01:05  来源:igfitidea点击:

How do you use LINQ with Sqlite

c#.netlinqsqlite

提问by minty

Would someone explain how to get LINQ working with Sqlite.

有人会解释如何让 LINQ 与 Sqlite 一起工作。

回答by CMS

Check this provider:

检查此提供程序:

SqlLite Linq Provider

SqlLite Linq 提供程序

Also you can consider using SQL Compactwhich has very good LINQ-to-SQL support.

您也可以考虑使用具有非常好的 LINQ-to-SQL 支持的SQL Compact

回答by Vin

Yup there is a SqlLite Linq Provideras mentioned by CMS

是的,CMS 提到了一个SqlLite Linq Provider

Check out SQL server compact and it works well with Linq

查看 SQL 服务器紧凑型,它与 Linq 配合良好

There is another thread on SO which you should check

SO上还有另一个线程,您应该检查一下

回答by Luke Foust

I would like to add that you can use Linq to Sql with SqlLite with a couple of stipulations:

我想补充一点,您可以将 Linq to Sql 与 SqlLite 一起使用,但有几个规定:

  1. You cannot use the Linq to Sql designer which means you have to hand roll your classes.
  2. You have to be careful not to do certain operation which will result in Sql code which is not supported by SqlLite.
  1. 您不能使用 Linq to Sql 设计器,这意味着您必须手动滚动您的类。
  2. 您必须小心不要执行某些操作,这会导致 SqlLite 不支持的 Sql 代码。

For example, you cannot use FirstOrDefault() in any of your Linq queries because it will result in something like:

例如,您不能在任何 Linq 查询中使用 FirstOrDefault(),因为它会导致如下结果:

select top 1 * from table where ...

Since SqlLite doesn't support the "top 1" syntax, you will gt a runtime Sql error.

由于 SqlLite 不支持“top 1”语法,您将 gt 运行时 Sql 错误。

Other than that, I have been using Linq to Sql with SqlLite with great success for basic CRUD operations.

除此之外,我一直在使用 Linq to Sql 和 SqlLite,在基本 CRUD 操作方面取得了巨大成功。

回答by Alex

The link provided by CMS doesn't work anymore. I have used this oneas it now seems to be baked into their SQL lite ADO .NET provider.

CMS 提供的链接不再有效。我已经使用这个一个,因为它现在似乎会烤到自己的SQL精简版ADO .NET提供。

Unfortunately they still don't support the designer mode of VS for creating classes :(

不幸的是,他们仍然不支持 VS 的设计器模式来创建类:(

Also be aware that SQL Server compact doesn't support the design mode for LINQ classes! However if you want to use the entity framework the designer does work for SQL lite and SQL Server compact :)

另请注意,SQL Server compact 不支持 LINQ 类的设计模式!但是,如果您想使用实体框架,设计器确实适用于 SQL lite 和 SQL Server compact :)

回答by Sasha

On this time there is NO good toolsto do this!

目前没有好的工具可以做到这一点!

LINQ providers for SQLite all is in alpha stage (for example:dblinq2007). And it is very big risk to use it in commercial purpose! So maybe in future...

SQLite 的 LINQ 提供程序都处于 alpha 阶段(例如:dblinq2007)。并且用于商业目的是非常大的风险!所以也许在未来...

If you want ot use ADO.NET there is good ove: phxsoftware.

如果你想使用 ADO.NET,有一个很好的方法:phxsoftware

回答by Ed Power

Joe Albahari's LINQPad now supports Sqlite: http://www.linqpad.net/Beta.aspx. The one LINQ tool to rule them all.

Joe Albahari 的 LINQPad 现在支持 Sqlite:http: //www.linqpad.net/Beta.aspx。统治所有这些的一个 LINQ 工具。

回答by Ethan

You can use this: http://code.google.com/p/dblinq2007. Although it looks like the project is still in Alpha stage, IMO it is actually very stable now. Of course if you have a huge project, it is better to consider using something else like MySQL or SQL Compact. I don't like SQL Server, because it is too bloated, and offers not many more functionalities over SQL Compact or MySQL

您可以使用它:http: //code.google.com/p/dblinq2007。虽然看起来项目还处于 Alpha 阶段,但 IMO 现在实际上非常稳定。当然,如果你有一个庞大的项目,最好考虑使用其他的东西,比如 MySQL 或 SQL Compact。我不喜欢 SQL Server,因为它太臃肿了,并且提供的功能比 SQL Compact 或 MySQL 多