I need to pass list of ids to IN
. I tried with below code but does not work. What is the issue with this code?
// SampleDBQueryType- is DbQuery
databaseContext.SampleDBQueryType.FromSql(@"
SELECT *
FROM SampleTable
WHERE UserObjectId IN (@userIds)",
new SqlParameter("userIds", GetCommaSeparatedStringValueForDbQuery(thirdPartyUserIds)))
.ToList();
// Returns => "'id1', 'id2'"
private string GetCommaSeparatedStringValueForDbQuery(IEnumerable<string> values)
{
string queryFilter = string.Empty;
values.ToList().ForEach(v =>
{
queryFilter = string.IsNullOrEmpty(queryFilter) ? $"'{v}'" : $"{queryFilter},'{v}'";
});
return queryFilter;
}
1条答案
按热度按时间beq87vna1#
You will have to do something like this: