I have this 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">
When I call it and try to pass null for the price column, which accepts a null in the database, I get an error. Is this possible?
Table definition:
[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
As per Dimitry Sevastianov's comment, here is the solution.
First, assigned true to the parameter AllParametersOptional:
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"
, AllParametersOptional = true>
Next, make call such as this:
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)