Personally I would layout my table structure so that data i wanted to query in that manner was not in a csv list in a table column.
If you are determined to use a sql stored procedure you can use the below. You can create a table type and pass it into the application you can then use the string_split function to turn your csv list into a table you can query and the all operator to check if it everything in your table parameter is there. The last bit where i call the procedure you would not do you would instead call the stored procedure in your c#, in c# you can create a datatable with a single string column called StringValue populate it with your list of filter colours and submit it as a sql parameter(note you need to tell it the name of your user defined type or you will get an error.)
CREATE DATABASE Mycolours;
go
USE Mycolours
GO
/****** Object: Table [dbo].[Colours] Script Date: 24/04/2019 23:13:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Colours](
[ColourID] [int] NOT NULL,
[ColourList] [nvarchar](50) NOT NULL
) ON [PRIMARY]
GO
GO
insert into [Colours](ColourID,ColourList) values(1,'blue,green,red'),(2,'green'),(3,'blue,green,red,black'),(4,'orange,blue,green,red,gray')
/****** Object: StoredProcedure [dbo].[SPGetAllMyColours] Script Date: 24/04/2019 23:14:10 ******/
SET ANSI_NULLS ON
GO
GO
/****** Object: UserDefinedTableType [dbo].[StringValues] Script Date: 24/04/2019 23:14:32 ******/
CREATE TYPE [dbo].[StringValues] AS TABLE(
[StringValue] [nvarchar](50) NOT NULL,
PRIMARY KEY CLUSTERED
(
[StringValue] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[SPGetAllMyColours]
@colours dbo.StringValues READONLY
AS
BEGIN
select * from colours where not exists(select StringValue from @colours where StringValue = all(select value from string_split(colours.ColourList,',')));
END
GO
GO
DECLARE @return_value int
declare @filterColours dbo.StringValues;
insert into @filterColours(StringValue) values('blue'),('green'),('red');
EXEC @return_value = [dbo].[SPGetAllMyColours] @filterColours
SELECT 'Return Value' = @return_value
GO
ColorsToFilter
/colorsToFilter
aList<string>
or a table or IQueryable from the database in your LINQ epression? How can it be tested if it doesn't work in EF6? Your best bet is to use anExpression
writer to create a predicate that is acceptable to EF, assumingcolorsToFilter
is a short list.