Hi I need to find data in a table by one or all properties, my idea is to fill an entity and make a search by all properties if the parameter is not null
I have 2 ideas for this but i dont know if is posible for both cases.
If there is a better way im all ears too :P
Thanks and regards
First set an entity and use it to search.
public bool find(nullable<int>param1,nullable<string>param2,nullable<string>param3)
{
Entity e = new Entity();
e.prop1 = param1;
e.prop2 = param2;
e.prop3 = param3;
var results = dbContext.....(e);
}
or my second idea was to ask if parameter is not null to add it to the query
public bool find(nullable<int>param1,nullable<string>param2,nullable<string>param3)
{
var results = dbContext.where(
if (param1!=null) e=> e.prop1 == param1,
if (param2!=null) e=> e.prop2 == param2,
if (param3!=null) e=> e.prop3 == param3);
}