MVC3 / EF - 更改模型...数据库架构不匹配
我一直在关注 ASP.Net 电影数据库教程,一切都很顺利。
我刚刚更改了模型并添加了一个属性。请说我好奇,但我不想遵循仅删除数据库的指南 - 我想看看是否可以修改。
正确错误是由于不匹配而出现的 - 这是预期的。
我将评级列添加到数据库中,一切正常。
因为我想按照教程进行操作并了解 DropCreateDatabaseIfModelChanges
- 但是,我只是收到错误无效的列名称“Ratings”。
接下来,我删除了评级列, 时间,ModelHash
条目没有改变,我不知道它如何知道现在和以前之间存在差异。
所以 - 1)我搞砸了什么吗?
2)我该如何解决?
3) 之前它怎么知道某些东西已经改变,但现在哈希值没有改变时却不知道?
4)您还有什么可以提供的建议吗?
I have been following the ASP.Net Movie Database Tutorial, and it was all going well.
I have just changed the model and added an attribute. Call me curious, but I didn't want to follow the guide of just drop the database - I wanted to see if I can modify.
The correct error came up about a mismatch - which was expected.
I added the ratings column to the database, and everything worked.
Next, I deleted the ratings column as I wanted to follow the tutorial and learn about DropCreateDatabaseIfModelChanges
- however, I just get the error Invalid column name 'Ratings'.
In all this time, the ModelHash
entry has not changed, and I have no idea how it know there is a difference between now or before.
So - 1) Have I screwed something up?
2) How can I fix?
3) How did it know before that something has changed, but not now when the hash hasn't changed?
4) Is there any additional advice you can give?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的描述一定不正确,因为尽管手动添加了
Rating
列,但正确的行为仍会引发异常。此行为的工作原理如下:
EdmMetadata
的新表。EdmMetadata
包含两列 -Id
和ModelHash
。手动添加
Rating
列不会更改存储的哈希值,但模型的哈希值会有所不同。通过删除
IncludeMetadataConvention
约定可以完全消除此行为:I think you description must be incorrect because correct behavior will throw the exception despite of manually added
Rating
column.This behavior works as follows:
EdmMetadata
is added.EdmMetadata
contains two columns -Id
andModelHash
.Adding manually
Rating
column will not change stored hash but hash of the model will be different.This behavior can be completely removed by removing
IncludeMetadataConvention
convention: