我对Entity Framework和C#相当新,所以如果我描述问题的能力很小,我很抱歉。
我在Azure上托管了一个.NET Web Forms项目,该项目使用Entity Framework来处理所有数据库表。我最近遇到了一个问题,我正在调试并创建了测试记录,一旦使用Microsoft SQL Server Management Studio解决了问题,我就删除了这些记录。不幸的是,我现在收到以下错误:
"支持' RegSysContext'自创建数据库以来,上下文已更改。考虑使用Code First Migrations来更新数据库"
RegSysContext类可以在下面看到。
据我所知,这是由实体框架使用的元数据不再与数据库匹配引起的。数据库中的数据是必不可少的,否则我只是擦掉它而忘记它。
如何在托管的Web应用程序上解决此问题,以及如何在不导致此问题的情况下编辑数据库?
提前致谢!
public class RegSysContext : DbContext
{
// Default Constructor for the context class
public RegSysContext() : base("RegSys")
{
}
// Properties of the context class
public DbSet<CustomerAccountMembership> AccountMembershipRecords { get; set; }
// For Organization Account functionality
public DbSet<RegSysAccount> RegSysAccounts { get; set; }
public DbSet<Subscription> Subscriptions { get; set; }
public DbSet<SubscriptionRecord> SubscriptionRecords { get; set; }
public DbSet<PaymentInfo> PaymentAccountInfoRecords { get; set; }
// For Auction functionality
public DbSet<Auction> auctions { get; set; }
public DbSet<AuctionItem> auctionItems { get; set; }
public DbSet<AuctionLot> auctionLots { get; set; }
public DbSet<AuctionDonation> auctionDontations { get; set; }
public DbSet<AuctionSale> auctionSales { get; set; }
public DbSet<ItemInAuctionRecord> itemInAuctionRecords { get; set; }
// For Event functionality
public DbSet<Event> events { get; set; }
public DbSet<EventParticipant> eventParticipants { get; set; }
public DbSet<RegistrationPeriod> registrationPeriods { get; set; }
public DbSet<RegType> regTypes { get; set; }
public DbSet<RegPrice> regPrices { get; set; }
public DbSet<EventCategory> EventCategories { get; set; }
//public DbSet<RegistrationConfig> regConfigs { get; set; }
//public DbSet<RegFormConfig> regFormConfigs { get; set; }
// For Organization functionality
public DbSet<Lodge> Lodges { get; set; }
// For Participant functionality
public DbSet<Participant> Participants { get; set; }
public DbSet<Charge> Charges { get; set; }
public DbSet<EventParticipantToParticipantLinker> EventParticipantLinks { get; set; }
// For System functionality
public DbSet<RegSysMessage> RegSysMessages { get; set; }
public DbSet<Transaction> Transactions { get; set; }
// For Trading Post functionality
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<CartItem> ShoppingCartItems { get; set; }
public DbSet<ProductInventory> ProductInventories { get; set; }
public DbSet<TradingPost> TradingPosts { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
public DbSet<ProductSale> ProductSales { get; set; }
public DbSet<SpecialOffer> SpecialOffers { get; set; }
}
答案 0 :(得分:0)
将此行添加到RegSysContext
类中的构造函数中:
Database.SetInitializer<RegSysContext>(null);
这行代码告诉Entity Framework是否创建数据库。将null
传递给IDatabaseInitializer strategy
参数,基本上完全禁用了数据库的初始化(因为它已经存在)