F#:将数据加载到 SQL 服务器时出现问题
F#: Trouble with loading data into SQL Server
我是编程新手,F# 是我的第一语言。
我想使用 F# 代码将数据加载到 SQL 服务器数据库中。这是应该存储我的数据的 table:
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
和Score3
应该包含评委的分数,有时可能无法获得。
这是我用于加载数据的 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# 代码时,我收到以下错误消息:
This expression was expected to have type
string
but here has type
'a * 'b
显然,编译器解释了这部分
"None", Score2 = ...
作为元组。
我尝试在网上搜索解决方案,但还没有找到。
我应该做哪些更改才能将数据加载到 SQL 服务器?
将 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.
我是编程新手,F# 是我的第一语言。
我想使用 F# 代码将数据加载到 SQL 服务器数据库中。这是应该存储我的数据的 table:
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
和Score3
应该包含评委的分数,有时可能无法获得。
这是我用于加载数据的 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# 代码时,我收到以下错误消息:
This expression was expected to have type
string
but here has type 'a * 'b
显然,编译器解释了这部分
"None", Score2 = ...
作为元组。
我尝试在网上搜索解决方案,但还没有找到。
我应该做哪些更改才能将数据加载到 SQL 服务器?
将 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.