简体   繁体   English

在asp.net MVC中使用嵌入式MySQL?

[英]Using inline mysql in asp.net mvc?

I have an MVC app that has inline SQL all over the place. 我有一个MVC应用,该应用到处都有内联SQL。 I am currently using MySQL and was curious if it would be a good idea to move the inline sql into functions or routines. 我当前正在使用MySQL,并且很好奇将内联sql移入函数或例程是否是个好主意。 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? 有替代方法吗?

It is better to keep your sql statements out of c# code. 最好使sql语句脱离c#代码。 There are couple of advantages, 有几个优点,

  1. As you mentioned, you don't need a build everytime you change any sql code 如前所述,每次更改任何sql代码时都不需要构建
  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 另外,您也可以尝试使用EntityFramework作为替代方法,在这里您无需担心sql语句

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM