如何告诉 EF Code First 仅删除使用 DbSet 定义的表,而不删除同一数据库中的其他表(Memberhisp 表)?

发布于 2024-12-23 17:18:37 字数 1016 浏览 4 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉态萌生 2024-12-30 17:18:37

使用您自己的自定义逻辑实现您自己的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文