Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Expression And Filter

public async Task<UserData> GetUserByName(string name)

​    {

​      BinaryExpression filter = null;
​      var data = new Dictionary<string, string>();
​      data.Add("name", name);
​      data.Add("technology", ".Net");
​      var userData = Expression.Parameter(typeof(UserData));
​      foreach (var toProcess in data)
​      {
​        var memberExpression = Expression.PropertyOrField(userData, toProcess.Key);
​        var constantExpression = Expression.Constant(toProcess.Value);
​        var binaryExpression = Expression.Equal(memberExpression, constantExpression); 
​        filter = (filter != null) ? Expression.And(filter, binaryExpression) : binaryExpression;

​      } 
​      Expression<Func<UserData, bool>> lambda = Expression.Lambda<Func<UserData, bool>>(filter, userData);
​      return await _dbContext.UserData.Where(lambda).FirstOrDefaultAsync();
​    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: unittest servicector automapper 
Csharp :: PasswordBox Helper 
Csharp :: string with starting zero to int c# 
Csharp :: Difference between IHostingEnvironment and IWebHostEnvironment ? 
Csharp :: open html file in browser using c++ 
Csharp :: c# read csv file save to database dynamically 
Csharp :: linked list follow what in c# 
Csharp :: c# class where T : enum 
Csharp :: {} is this used for code blocks in c# 
Csharp :: ado .net nullable int datareader 
Csharp :: check if variable less than in f# 
Csharp :: c# parsing datetime from string irrespctive of culture 
Csharp :: unity script template location 
Csharp :: get path revit link unloaded 
Csharp :: Retrieving a value in one class that is set in another 
Csharp :: disable quickedit c# 
Csharp :: unity play audio from particle system 
Csharp :: c# string replace multiple matches with one charactar 
Csharp :: unitydont play sound until finsihed 
Csharp :: c# asp.net gridview selected row unselect 
Csharp :: simplified if statement c# 
Csharp :: Handling aggregation responses with NEST c# 
Csharp :: c# string is all zeros 
Csharp :: c# get buttons row and column in grid 
Csharp :: c# generate random key with specified length 
Csharp :: c# prototype function 
Csharp :: how to set an expiry date on a program 
Csharp :: how to make header in unity public variables 
Csharp :: jsonconvert serializeobject and jsonconvert deserialize to list 
Csharp :: DotNet web Api Token based Authentication 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =