0

I have an MVC app that has inline SQL all over the place. I am currently using MySQL and was curious if it would be a good idea to move the inline sql into functions or routines. This way, if it needed to be changed, I would just have to change the routine or function at the database level instead of at the code level which would require a new build. Is there an alternative approach?

1 Answer 1

1

It is better to keep your sql statements out of c# code. There are couple of advantages,

  1. As you mentioned, you don't need a build everytime you change any sql code
  2. You will get slight performance improvisation
  3. More maintainability and readability

Also you could try EntityFramework as an alternate, where you don't need to bother about sql statements

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so my options are using an entity framework or routines? Thanks for the entity framework suggestion. If I change the underlying database and the orm is built upon that, wouldn't that essentialy require a rebuild?
If you change the schema of database, for sure you have to refresh EF POCO, and depends upon your change even you might go for refactoring as well. In EF your entities are CLR native objects and you write your business logic more in CLR language C#/VB. Naturally you require a rebuild when you change a c# code. This is a different context and i don't think there is a point in comparing EF related changes with inline sql statements changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.