Is there a way to use LINQ query syntax with .NET 3.0 projects?

[亡魂溺海] 提交于 2019-12-01 19:36:23

问题


I have a project which can only be deployed on a server running .NET 3.0. I desperately want to use LINQ to simplify some excruciatingly tedious logic. Is there a simple way to accomplish this? I'll settle for any syntax.

Thanks a lot


回答1:


Since .NET 2.0 through 3.5 all run on the CLR 2.0, all the LINQ stuff is just a bunch of libraries. If you include the DLLs that are missing on your version of the framework, it will work just fine.

As Patrick says, the key 3.5 DLLs are System.Core.dll (which provided System.Linq) and System.Data.Linq.dll (for Linq-to-SQL).

If you do this, I think you need System.dll from at least .NET 2.0SP1 I believe.

LINQBridge, as cited by Marc, works by re-implementing the functionality but only for Linq-to-Objects I believe.

Another option is to use these same DLLs (System.Core.dll and System.Data.Linq.dll) from the Mono project. They have reimplemented all of LINQ. The Linq-to-Sql stuff is perhaps a little immature but it does have the virtue of working with other databases than just MSSQL.

http://mono-project.com/Main_Page

This removes any question of the legality of distributing Microsoft DLLs with your application.




回答2:


A coworker used LINQBridge and had success.




回答3:


Taken from http://codebeat.wordpress.com/2008/06/23/using-linq-in-net-30/:

  1. First, configure the target framework of the projects using Linq to .NET 3.0. The .NET 3.5 references will be removed.
  2. Then, copy System.Data.Linq.dll and System.Core.dll in the solution, wherever you prefer (in my case, the root folder).
  3. Add them as references in all the corresponding projects. Visual Studio will warn about the assemblies need a later version of the framework. Press Yes.
  4. Set the SpecificVersion property of the references to true. This will prevent compiling errors.

I tried this, and it worked, but beware of Mike Atlas's caution about the legal ramifications of deploying these 2 files.



来源:https://stackoverflow.com/questions/3348348/is-there-a-way-to-use-linq-query-syntax-with-net-3-0-projects

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