如何告诉 EF Code First 仅删除使用 DbSet 定义的表,而不删除同一数据库中的其他表(Memberhisp 表)?
我将 EF Code First 与 DontDropDbJustCreateTablesIfModelChanged
结合使用。
我使用它是因为我正在部署到 Appharbor,这样只有表被删除/重新创建,而不是数据库。
在同一个数据库中,我使用 aspnet_regsql
工具为成员资格和角色提供程序生成表。
如何使 EF Code First 从我的项目中删除/重新创建表,而不是成员资格/角色提供者的表?
这是我得到的错误:
Cannot use DROP TABLE with 'vw_aspnet_Applications' because 'vw_aspnet_Applications' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_Users' because 'vw_aspnet_Users' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_MembershipUsers' because 'vw_aspnet_MembershipUsers' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_Roles' because 'vw_aspnet_Roles' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_UsersInRoles' because 'vw_aspnet_UsersInRoles' is a view. Use DROP VIEW.
drop table [vw_aspnet_Applications]
drop table [vw_aspnet_Users]
drop table [vw_aspnet_MembershipUsers]
drop table [vw_aspnet_Roles]
drop table [vw_aspnet_UsersInRoles]]
I am using EF Code First with DontDropDbJustCreateTablesIfModelChanged
.
I am using this because I am deploying to Appharbor, and this way only the tables are drop/recreated and not the database.
In the same database I used the aspnet_regsql
tool to genarate tables for Membership and Role provider.
How can I make EF Code First to drop/Recreate the tables from my project, and not the ones for Membership/Role provider?
This is the error i get:
Cannot use DROP TABLE with 'vw_aspnet_Applications' because 'vw_aspnet_Applications' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_Users' because 'vw_aspnet_Users' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_MembershipUsers' because 'vw_aspnet_MembershipUsers' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_Roles' because 'vw_aspnet_Roles' is a view. Use DROP VIEW.
Cannot use DROP TABLE with 'vw_aspnet_UsersInRoles' because 'vw_aspnet_UsersInRoles' is a view. Use DROP VIEW.
drop table [vw_aspnet_Applications]
drop table [vw_aspnet_Users]
drop table [vw_aspnet_MembershipUsers]
drop table [vw_aspnet_Roles]
drop table [vw_aspnet_UsersInRoles]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您自己的自定义逻辑实现您自己的 IDatabaseInitializer 以排除这些表(或只是不包含它们)
请参阅此处的示例:
https://gist.github.com/895730
Implement your own IDatabaseInitializer with your own custom logic to exclude these tables (or just not include them)
See an example here:
https://gist.github.com/895730