我有这个SqlCommandProvider:
type Insert_NewFeed =
SqlCommandProvider<
"
INSERT INTO info.LiveFeed
( Id ,
MediaId ,
FactTypeId ,
Price ,
Description ,
PhoneNumber ,
Email ,
Website ,
CreateDate ,
CityId
)
VALUES ( @id , -- Id - nvarchar(128)
@mediaId , -- MediaId - nvarchar(128)
@factTypeId , -- FactTypeId - int
@price , -- Price - decimal
@description , -- Description - nvarchar(max)
@phoneNumber , -- PhoneNumber - nvarchar(50)
@email , -- Email - nvarchar(max)
@website , -- Website - nvarchar(max)
@createDate , -- CreateDate - datetime2
@cityId -- CityId - int
)
", Admin.connectionString, ConfigFile = "Web.config">
当我调用它并尝试为price列传递null时,它在数据库中接受null,我收到错误。这可能吗?
表格定义:
[Id] [nvarchar](128) NOT NULL,
[MediaId] [nvarchar](128) NOT NULL,
[FactTypeId] [int] NOT NULL,
[Price] [decimal](18, 2) NULL,
[Description] [nvarchar](max) NULL,
[PhoneNumber] [nvarchar](50) NULL,
[Email] [nvarchar](max) NULL,
[Website] [nvarchar](max) NULL,
[CreateDate] [datetime2](7) NOT NULL,
[CityId] [int] NULL
答案 0 :(得分:1)
根据Dimitry Sevastianov的评论,这是解决方案。
首先,将参数AllParametersOptional:
赋值为truetype Insert_NewFeed =
SqlCommandProvider<
"
INSERT INTO info.LiveFeed
( Id ,
MediaId ,
FactTypeId ,
Price ,
Description ,
PhoneNumber ,
Email ,
Website ,
CreateDate ,
CityId
)
VALUES ( @id , -- Id - nvarchar(128)
@mediaId , -- MediaId - nvarchar(128)
@factTypeId , -- FactTypeId - int
@price , -- Price - decimal
@description , -- Description - nvarchar(max)
@phoneNumber , -- PhoneNumber - nvarchar(50)
@email , -- Email - nvarchar(max)
@website , -- Website - nvarchar(max)
@createDate , -- CreateDate - datetime2
@cityId -- CityId - int
)
", Admin.connectionString, ConfigFile = "Web.config"
, AllParametersOptional = true>
接下来,拨打电话:
let rowResult = (new Insert_NewFeed())
.Execute(Some fC.Id, Some fC.MediaId, Some fC.FactTyeId,
None,
Some fC.Description, Some fC.PhoneNumber, Some fC.Email,
Some fC.Website, Some fC.CreateDate, Some fC.CityId)