I am using Entity Framework EDMX which automatically generates the needed functions i need for stored procedure executions as part of an auto generated class based on DBContext class.
for example, this is an auto generated function to execute stored procedure:
public virtual ObjectResult<Company> GetCompanies(string companyName)
{
var companyNameParameter = companyName != null ?
new ObjectParameter("CompanyName", companyName) :
new ObjectParameter("CompanyName", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Company>("GetCompanies", companyNameParameter);
}
Since i am using dynamic SQL inside some of the stored procedure, i would like to override ExecuteFunction and use "Custom ExecuteFunction" function to add some sanitize functions there which will loop over each parameter and sanitize it. i am wondering, maybe i can create a custom ObjectContext class and use it somehow?
How can i do it in a way that i will still be able to use the EDMX Entity framework auto generates functions?
i know that there is some solutions to sanitize the parameters inside the SP but i still want to learn how can i use custom ExecuteFunction function or custom ObjectContext together with EDMX.
EXEC (@sql)- then: don't do that - you should be usingEXEC sp_executesql @sql, N'{args definition}', @arg0, @arg1, ...- which allows you to fully parameterize dynamic SQL; more context: learn.microsoft.com/en-us/sql/relational-databases/…