In ADO.Net I created a DAL file that took parameters from the user and if they were not null, the query got extended based on if statements. Now I want to do the same in Entity Framework. I have searched a number of sites including Stack Overflow but failed to get my satisfactory answer. for Reference, the following link also could not help me
Select Query with Where condition depending on list values in asp.net
the required scenario is
cmd.text = "SELECT FROM tbl_name WHERE id>0 "
if(param_value != null)
{
cmd.text += " AND (param_name = '@param_value')";
if(!cmd.contains("param_name"))
cmd.parameters.addwithvalue("param_name", @param_value);
cmd.parameters["param_name"] = @param_value;
}
// proceed further with cmd.text
please ignore the syntax right now, I just wanted to convey my concept of what I want to do.
I want to apply the same concept for Entity Framework
Well two days back I found a scenerio in wheich the query (text) was built in an aspx.cs file and it was passed as it is to a custom built function in DAL which passed the text to cmd.text and processed the rest of retrieval in an ADO.net style.
This method is potentially dangerious as anyone with a bit knowlege can break this security down to grounds. I want to create a query that has parameters as well as its vales like I have shown in above code block.