简体   繁体   English

F#:将数据加载到SQL Server中时遇到问题

[英]F#: Trouble with loading data into SQL Server

I am new to programming and F# is my first language. 我是编程新手,F#是我的第一语言。

I want to load data into a SQL Server database using F# code. 我想使用F#代码将数据加载到SQL Server数据库中。 Here is the table that is supposed to store my data: 这是应该存储我的数据的表:

CREATE TABLE [dbo].[Scores](
    [EventName] [nvarchar](100) NOT NULL,
    [Winner] [nvarchar](50) NOT NULL,
    [Loser] [nvarchar](50) NOT NULL,
    [Score1] [nvarchar](10) NOT NULL,
    [Score2] [nvarchar](10) NOT NULL,
    [Score3] [nvarchar](10) NOT NULL
) ON [PRIMARY]

Score1 , Score2 and Score3 are supposed to contain judges' scores, which might be unavailable sometimes. Score1Score2Score3都应该包含法官的成绩,这可能是不可用的时候。

Here is my F# code for loading the data: 这是我的F#代码,用于加载数据:

            new dbSchema.ServiceTypes.Fights(EventName = fightSummary.event,
                                            Winner = fightSummary.winner.Value,
                                            Loser = fightSummary.loser.Value,

                                            Score1 = if judgesScoresExist then
                                                        fightSummary.judgesScores.Value.[0]
                                                     else
                                                        "None",
                                            Score2 = if judgesScoresExist then
                                                        fightSummary.judgesScores.Value.[1]
                                                     else 
                                                        "None",
                                            Score3 = if judgesScoresExist then
                                                        fightSummary.judgesScores.Value.[2]
                                                     else "None")

When I try to run the F# code above, I receive the following error message: 当我尝试运行上面的F#代码时,收到以下错误消息:

This expression was expected to have type string but here has type 'a * 'b 该表达式应具有string类型,但此处具有类型'a *'b

Apparently, the compiler interprets the part 显然,编译器会解释该部分

"None", Score2 = ...

as a tuple. 作为元组。

I tried searching online for a solution, but have yet to find one. 我尝试在线搜索解决方案,但尚未找到解决方案。

What changes should I make so that I can load my data into SQL Server? 我应该进行哪些更改才能将数据加载到SQL Server中?

Put if then else expressions in parenthesis: if then else表达式放在括号中:

let v = new Fights(EventName = fightSummary.event,
                   Winner = fightSummary.winner.Value,
                   Loser = fightSummary.loser.Value,

                   Score1 = (if judgesScoresExist then
                               fightSummary.judgesScores.Value.[0]
                             else
                               "None"),
                    ...) // etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM