我有一个字段,"Code3"
在SQL中的值像"A,B,C"
和在我的linq代码,我怎么能选择"Code3"
包含"B"
的记录?
Dim dc = New SchedulerDataContext()
Dim dataset As IEnumerable(Of Events_Tran)
dataset = From ev In dc.Events_Trans
Where ev.Code3.Split(",").ToString = "A" Select ev
如果您不能将这些值拆分到它们自己的表中(您可能应该这样做),那么这将为您完成这项工作。If检查该值是否出现在列的开头、中间或末尾,以及它是否是唯一的值:
dataset = From ev In dc.Events_Trans _
Where ev.Code3.StartsWith("A,") _
Or ev.Code3.Contains(",A,") _
Or ev.Code3.EndsWith(",A") _
Or ev.Code3 = "A" _
Select ev