我应该在SqlClr中运行F#吗?

时间:2021-08-07 06:02:45

I need to run .Net code in Sql and I'm trying to decide between F# and C#. I'm doing more and more code in F# nowadays so if it's not too impractical, I'd like it to be F#.

我需要在Sql中运行.Net代码,我试图在F#和C#之间做出决定。我现在在F#中做的代码越来越多,所以如果它不是太不切实际,我希望它是F#。

Is it possible to coerce VS2010 to deploy my F# assemblies (and their references) to Sql Server, in the same nice way a C# project does?

是否有可能强制VS2010将我的F#程序集(及其引用)部署到Sql Server,这与C#项目的做法相同?

Would you recommend/not recommend running F# in Sql? Why?

你会建议/不建议在Sql中运行F#吗?为什么?

EDIT: I agree that the language is better, that is not the question. I was mainly wondering if anyone had experience with using F# in SqlClr and specifically if the tools can offer a simple workflow for development, i.e. Deploy in VS2010.

编辑:我同意语言更好,这不是问题。我主要想知道是否有人在SqlClr中使用F#的经验,特别是如果这些工具可以提供简单的开发工作流程,即在VS2010中部署。

EDIT 2: I'm experimenting with this, and registering manually is downright painful. Besides CREATE ASSEMBLY you have to register each function, sp, aggregate etc. You also have to drop them in the right order first, if they exist, lest you get a DROP ASSEMBLY failed because 'Nibbler' is referenced by object 'Hello'.

编辑2:我正在试验这个,手动注册是非常痛苦的。除了CREATE ASSEMBLY,你必须注册每个函数,sp,聚合等。你还必须先按正确的顺序删除它们,如果它们存在,以免你得到DROP ASSEMBLY失败,因为'Nibbler'被对象'Hello'引用。

I then had the idea to use a C# project as a front end and have this project reference an F# project, just to have all this deploying taken care of automatically. Turns out you can only reference other C#/VB Sql Clr projects, or assemblies that are already referenced in Sql. This could still simplify deployment though, as all creation/deletion of functions etc would be handled automatically. Then, for deploying from test to production, I would just generate scripts from all the stuff that is registered in my test environment.

然后,我有了使用C#项目作为前端的想法,并让这个项目引用了一个F#项目,只是为了让所有这些部署自动完成。事实证明,您只能引用其他C#/ VB Sql Clr项目或Sql中已引用的程序集。这仍然可以简化部署,因为所有功能的创建/删除等都将自动处理。然后,为了从测试部署到生产,我只会从我在测试环境中注册的所有内容生成脚本。

PS. I also tried fiddling with the .fsproj file, diffing with the .csproj of a C# Clr project, to enable deployment to no avail.

PS。我还试图摆弄.fsproj文件,与C#Clr项目的.csproj进行区分,以使部署无济于事。

2 个解决方案

#1


12  

If you have trouble with FSharp.Core and other references in the SQL CLR context, you could try the --standalone compiler flag to cause external references to be embedded in the assembly that you deploy to SQL Server.

如果在SQL CLR上下文中遇到FSharp.Core和其他引用时遇到问题,可以尝试使用--standalone编译器标志,以便将外部引用嵌入到部署到SQL Server的程序集中。

#2


8  

I would recommend coding your CLR UDFs/procedures in F# for much the same reason I'd recommend coding almost anything in F# (see the numerous F# vs C# questions on SO). I can't think of a reason to prefer C# for anything. I haven't tried deploying assemblies to SQL Server using VS, but CREATE ASSEMBLY works just fine...and works the same, regardless of programming language.

我建议用F#编写你的CLR UDF /程序,原因与推荐用F#编写几乎任何东西的原因相同(参见SO上的大量F#和C#问题)。我想不出有什么理由更喜欢C#。我没有尝试使用VS将程序集部署到SQL Server,但CREATE ASSEMBLY工作正常...并且无论编程语言如何都可以正常工作。

#1


12  

If you have trouble with FSharp.Core and other references in the SQL CLR context, you could try the --standalone compiler flag to cause external references to be embedded in the assembly that you deploy to SQL Server.

如果在SQL CLR上下文中遇到FSharp.Core和其他引用时遇到问题,可以尝试使用--standalone编译器标志,以便将外部引用嵌入到部署到SQL Server的程序集中。

#2


8  

I would recommend coding your CLR UDFs/procedures in F# for much the same reason I'd recommend coding almost anything in F# (see the numerous F# vs C# questions on SO). I can't think of a reason to prefer C# for anything. I haven't tried deploying assemblies to SQL Server using VS, but CREATE ASSEMBLY works just fine...and works the same, regardless of programming language.

我建议用F#编写你的CLR UDF /程序,原因与推荐用F#编写几乎任何东西的原因相同(参见SO上的大量F#和C#问题)。我想不出有什么理由更喜欢C#。我没有尝试使用VS将程序集部署到SQL Server,但CREATE ASSEMBLY工作正常...并且无论编程语言如何都可以正常工作。