Nash
Nash

Reputation: 531

SQL Server "in" equivalent in .Net

I'm asking with my interest to learn:

Select * from Customer where CustomerId in(12,23,45);

Similarly is there any C#.Net Keyword for the same above?

Example: verify Date(month) not in Oct,Nov Dec. (not in SQL or LINQ)

I did it with Extension method( Ternary operator and || by verifying with month) I'm looking for simple way to verify, if exists.

Upvotes: 3

Views: 1550

Answers (3)

Giedrius
Giedrius

Reputation: 8540

You need to keep in mind though, that in querying SQL database there is one limitation though: set you're searching in can't be bigger than 2100 items, because each item is passed to sql server as separate parameter and SQL server allows max 2100 parameters per query. So unless you're sure that you won't have so many items in searchable set, I would suggest to use something like this.

Upvotes: 0

Icarus
Icarus

Reputation: 63966

No, there isn't but you can do something like:

bool contains = (new string[] {"Oct","Nov","Dec"}).Contains("Dec");

Upvotes: 1

the_joric
the_joric

Reputation: 12226

Threre is no keyword, however you can use the following construct:

using System.Linq;
...
(new [] {12, 23, 45}).Contains(customerID)

Upvotes: 11

Related Questions