Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

linq conditionnally add where clause

var query = from u in DataContext.Users
   where u.Division == strUserDiv 
   && u.Age > 18
   && u.Height > strHeightinFeet
   select u;

if (useAge)
   query = query.Where(u => u.Age > age);

if (useHeight)
   query = query.Where(u => u.Height > strHeightinFeet);

// Build the results at the end
var results = query.Select(u => new DTO_UserMaster
   {
     Prop1 = u.Name,
   }).ToList();
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# open config file by path 
Csharp :: An unhandled exception occurred during the execution of the current web request 
Csharp :: export xml 
Csharp :: Convert any class to a keyvaluepair 
Csharp :: what is C# 
Csharp :: webtest fullscreen extend window maximize 
Csharp :: Options Pattern how to use 
Csharp :: how to display only date from datetime in mvc view 
Csharp :: resharper render pages folder asp.net core 
Csharp :: how to make projectile track and go to specified enemy in unity 
Csharp :: internal static object ds 
Csharp :: best programming language for compression ratio 
Csharp :: unity Polymorphism 
Csharp :: downloading a large file asp boilerplate (abp) 
Csharp :: how to select class object from query c# 
Csharp :: bitter foods examplews 
Csharp :: Worker service as Windows Service 
Csharp :: how to validate decimal number with percision of (25, 4) iin c# 
Csharp :: unity predicts rigidbody position in x seconds 
Csharp :: windows form button image size 
Csharp :: wpf line intersect rectangle 
Csharp :: button Previous for picturebox c# 
Csharp :: polymorphism in c# 
Csharp :: c# mapper.map 
Csharp :: unity new input system get button down 
Csharp :: belgiumcampus 
Csharp :: MailChimp C# Api calls 
Csharp :: vbnet programatically convert type to db type 
Html :: html pound symbol 
Html :: html include jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =