繁体   English   中英

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

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

我是编程新手,F#是我的第一语言。

我想使用F#代码将数据加载到SQL Server数据库中。 这是应该存储我的数据的表:

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]

Score1Score2Score3都应该包含法官的成绩,这可能是不可用的时候。

这是我的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")

当我尝试运行上面的F#代码时,收到以下错误消息:

该表达式应具有string类型,但此处具有类型'a *'b

显然,编译器会解释该部分

"None", Score2 = ...

作为元组。

我尝试在线搜索解决方案,但尚未找到解决方案。

我应该进行哪些更改才能将数据加载到SQL Server中?

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