简体   繁体   English

我可以为允许为null的十进制列插入null吗

[英]Can I insert null for a decimal column that allows null

I have this SqlCommandProvider: 我有这个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. 当我调用它并尝试为价格列传递null时,该列在数据库中接受一个null,我得到一个错误。 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. 根据Dimitry Sevastianov的评论,这是解决方案。

First, assigned true to the parameter AllParametersOptional: 首先,将true分配给参数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)

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

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