[英]The null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type
[英]The null value cannot be assigned to a member with type System.Boolean which is a non-nullable value type
select new
{
countFair = (pstvte.Fair),
});
我已将列Fair的默认值设置为“false”。 现在,我在新字段中分配这个不可为空的布尔值,它给出了以下错误:
无法将null值分配给类型为System.Boolean的成员,该类型是不可为空的值类型
CREATE TABLE [dbo].[PostVote](
[PostVoteId] [bigint] IDENTITY(1,1) NOT NULL,
[PostId] [bigint] NOT NULL,
[UserId] [bigint] NOT NULL,
[Fair] [bit] NOT NULL,
[NotFair] [bit] NOT NULL,
CONSTRAINT [PK_PostVote] PRIMARY KEY CLUSTERED
(
[PostVoteId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PostVote] ADD DEFAULT ('False') FOR [Fair]
GO
ALTER TABLE [dbo].[PostVote] ADD DEFAULT ('False') FOR [NotFair]
GO
我想你需要改变你对countFair
的声明
从
bool countFair;
至
bool? countFair;
要么
做这样的事情
select new
{
countFair = (pstvte.Fair.HasValue ? pstvte.Fair.Value : false ),
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.