我的 web api 中有以下命令:
return Request.CreateResponse(HttpStatusCode.OK,
MyDBContext.DB.Database.SqlQuery<MyCustomerClass>("SELECT * FROM CUSTOMER").ToList());
这是表格:
CREATE TABLE [dbo].[Customer] (
[CustomerID] [int] NOT NULL,
[FirstName] [nvarchar](50) NOT NULL,
[LastName] [nvarchar](50) NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
([CustomerID] 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
我发现从 webApi 请求数据时,如果字段是null
返回的 JSON 结果,则返回结果中不包含该字段。这是预期的行为吗?