I have several methods with a common pattern, i want to write a generic function that will take the column name as input and give the same result.
private void Query138()
{
var products = (from p in _context.Products
where p.Manufacturer == null
select p);
foreach (var productItem in products)
{
productItem.Manufacturer = string.Empty;
_context.UpdateProduct(productItem);
}
}
private void Query139()
{
var products = (from p in _context.Products
where p.ModelNumber == null
select p);
foreach (var productItem in products)
{
productItem.ModelNumber = string.Empty;
_context.UpdateProduct(productItem);
}
}
i want to write a generic function that will take the column name as input for the above methods.
Example:
private void Update(Expression<Fun<T,string>> pred = null)
{
//use the input column to select the data
//use the input column to set the new value and update
}