我是 linq 的新手。我正在尝试编写一个 linq 查询,它将搜索数据库中的 3 个字段。但是,如果任何字段为空白或什么都没有,则它不会在查询中包含该字段。
搜索对象
Public Class Search
Public Property firstName As String
Public Property surname As String
Public Property address As String
End Class
桌子
CREATE TABLE [dbo].[user] (
[id] [int] IDENTITY(1,1) NOT NULL,
[firstName] [nvarchar](50) NULL,
[surname] [nvarchar](50) NULL,
[fullAddress] [nvarchar](1050) NULL
我的尝试,但这不会取回任何数据
(From it In db.user
Where (
searchItems.firstName IsNot Nothing
AndAlso it.firstName.Contains(searchItems.firstName))
AndAlso (searchItems.surname IsNot Nothing
AndAlso it.surname.Contains(searchItems.surname))
AndAlso (searchItems.address IsNot Nothing
AndAlso it.fullAddress.Contains(searchItems.address))
Select it).
ToList
我还需要将此限制为 250 条记录
提前感谢保罗