更改 ASP.NET MVC 应用程序中数据库字段的类型?
我有一个 asp.net mvc 2 应用程序,其中包含由实体框架 ORM 访问的 SQL Server 数据库。现在我发现我在数据库中的一个字段中使用了错误的数据类型 - int 而不是 double。
现在,这还不是一个大型商业应用程序,但它已经在我公司内部使用了。它工作正常,但用户需要能够输入十进制值而不仅仅是整数...
所以我的问题是,可以这么说,我可以在事后更改字段的类型,并且不会丢失已输入的数据?当然,我必须更改模型中对该字段的引用以及引用它的所有内容,但是有可能在不丢失数据的情况下吗?
我将不胜感激任何关于如何解决这个问题的建议!
I have an asp.net mvc 2 application with a SQL Server database accessed by the Entity Framework ORM. Now I found out I had used the wrong datatype for one of the fields in the database - int instead of double.
Now, this is not a big commercial application, but it is nevertheless already in use internally in my company. It works fine, but the users would need to be able to enter decimal values rather than just integers...
So my question is, can I change the type of the field after the fact so to speak, and not lose the data already entered? Of course I would have to change the references to this field in the model and everything that references it, but is it possible at all without losing the data?
I would appreciate any suggestions for how to go about solving this problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 int 而不是十进制,您所拥有的数据可能已经不正确,并且代码甚至会中断。当您从整数转换为十进制时,您不会丢失任何数据。您需要采取的步骤 -
您可能希望最后执行数据库步骤,以防您的资料处于活动状态并正在使用,在这种情况下,请在上传更改时执行此操作。
Well if you used int instead of decimal the data you have might have already been incorrect and code would even break. You wont lose any data in your case as you are going from int to decimal.Steps you need to take-
You might want to do the database step last in case your stuff is live and being used in that case do it when you upload the changes.