I am working at implementing a search feature into my MVC3 application. I’m looking to pass two parameters into and execute a stored procedure that will look basically something like this:
create procedure MyProc
(
@FirstParam nvarchar(50),
@SecondParam nvarchar(20)
)
as select * from MyTable where @FirstParam like @SecondParam
- MyTable has about 30 fields that will be returned for each object and I need to create a procedure like this for several tables, so I am trying to avoid using a SqlDataReader and converting the returned Sql data to C#.
- I would like to use something like this method but I am not sure if this can be done with multiple parameters.
- Ideally I would like to use EF4, but I have not found any good information on executing stored procedures while using EF4.
Any insight on the most painless way and/or best practice for executing this task will be greatly appreciated.
My sugestion is use dynamic linq (and here, and here). You can pass valid linq expressions as regular strings:
The benefits (IMO) is that you can keep the search logic in the application and, if you need to do this for many tables, you can create a T4 template to generate the bootstrap code for you.