- Aaron D'Hooghe
- SnapObjects
- Thursday, 16 November 2023 02:34 PM UTC
Hi,
I am using the LoadAsync() methode to load my object from the database.
I was wondering if there is a way to dynamically add a where clause.
I have class with a SqlParameter called Name. I use this parameter in a where clause. But this parameter can be null. Is there a way to remove te where clause when the parameter is null
example:
public async Task<IEnumerable<customer>> RetrieveAsync(string name)
{
var result = await _dataContext.SqlModelMapper.loadAsync<Customer>(name);
return result.ToList()
}
[SqlParameter("Name", typeof(string))]
[FromTable("Customers")]
[SqlWhere("Name = :Name")]
public class Customer {
public int Id { get; set; }
public string Name { get; set; }
}
If the parameter Name is null snapobjects will add "where Name = null" to the query, this will return no results ofcourse.
Is there a way to ingore the where when the parameter is null?
Kind regards,
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.