M
Mikael Janers
Hello!
I have a question that is not realy only C# but I didn't find any better
group...
What is the most common/best way to handle sql queries in C#
1) Should I use stored procedures ? I like them because I have all my
queries in one place, easy to find and update... But I dont like them
because you never know where they are used from. If you change one it might
affect some area of the application you didn't think about. Ofcourse you get
the speed advantage but I'd be happy to give that up for a better design.
2) Should I declare the sql query localy in the method that wants to execute
it ? This is the most appealing method to me. This way I know exactly what
scope the query can be executed in. I can safetly modify the query and know
other parts of the application will not be affected.
3) I saw some other method to declare the queries as static class members.
To me it seems like a mixture of the above 2. The scope for the queries are
well defined (similar to 2), but it might be huge . You can have your
queries in a region in the class that is easy to find and update (similar to
1).
There are probably as many methods to use as there are developers... but
please give me comments, what do you perfer and why ?
I have a question that is not realy only C# but I didn't find any better
group...
What is the most common/best way to handle sql queries in C#
1) Should I use stored procedures ? I like them because I have all my
queries in one place, easy to find and update... But I dont like them
because you never know where they are used from. If you change one it might
affect some area of the application you didn't think about. Ofcourse you get
the speed advantage but I'd be happy to give that up for a better design.
2) Should I declare the sql query localy in the method that wants to execute
it ? This is the most appealing method to me. This way I know exactly what
scope the query can be executed in. I can safetly modify the query and know
other parts of the application will not be affected.
3) I saw some other method to declare the queries as static class members.
To me it seems like a mixture of the above 2. The scope for the queries are
well defined (similar to 2), but it might be huge . You can have your
queries in a region in the class that is easy to find and update (similar to
1).
There are probably as many methods to use as there are developers... but
please give me comments, what do you perfer and why ?