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,
Below will give a InvalidOperationException saying "Missing parameter value(s)", so this won't work.
await _dataContext.SqlModelMapper.LoadAsync<Customer>();
King regards
I mistakenly believed LoadAsync with no arguments would just load all entries, but it seems there's a separate method for that:
LoadAll(), so please try replacing the functions.
Regards,
Francisco