如何告诉EF Code First只删除在同一个数据库中使用DbSet而不是其他(Memberhisp表)定义的表?(How to tell EF Code First to drop only the tables defined with DbSet and not others (Memberhisp tables) in the same database?)

我正在使用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]]

最满意答案

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

更多推荐