ef-migrations

adding a foreign key with Code First migration

╄→гoц情女王★ 提交于 2019-12-18 11:07:01
问题 I have an error when trying to update my database after adding a migration. Here are my classes before add-migration public class Product { public Product() { } public int ProductId { get; set; } public string Name { get; set; } public decimal Price { get; set; } public bool Istaxable { get; set; } public string DefaultImage { get; set; } public IList<Feature> Features { get; set; } public IList<Descriptor> Descriptors { get; set; } public IList<Image> Images { get; set; } public IList

MVC5: UserManager.AddToRole(): “Error Adding User to Role: UserId not found”?

久未见 提交于 2019-12-18 11:04:45
问题 I have been experimenting with MVC5/EF6 and trying out the new Identity Authentication with Code-First Migrations. Everything in the solution is currently building and I can add a Migration , but when I perform an update-database through the package manager console in VS2013, my Configuration.cs file fails to fully process my test data into my Tables and outputs Error Adding User to Role: UserId not found . I have tried explicitly setting a User ID and leaving it to be generated by the

How to use migrations on an existing db in production created using Entity Framework 4.1?

余生长醉 提交于 2019-12-18 10:56:08
问题 I have a system in production which was created with Entity Framework 4.1 Code First. Now, I have upgraded to 4.3 and need to apply migrations, but there's several use cases I need to cover: A new developer needs the database created from scratch with seed data. (The Seed() method also applies some unique indices.) The production environment needs only the unapplied changes applied. (But keep in mind that this DB was created in EF 4.1, which doesn't have migrations.) How do I create the

Code First Migrations and initialization error

[亡魂溺海] 提交于 2019-12-18 10:35:20
问题 I'm unsure about how to use the code first migration feature. In my understanding it should create my database if it's not existing already, and update it to the latest schema according to migration files. But I'm struggling with it, because I always get a lot of errors and I'm unsure overall how to use this properly.. internal class Program { private static void Main() { EntityFrameworkProfiler.Initialize(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data

How to correctly set foreign key constraint in one to many relationship in code first ASP.NET MVC 5 application

核能气质少年 提交于 2019-12-18 09:39:26
问题 So I have one document table and a ApplicationUser table. One user can upload multiple documents and a foreign key constraint has been applied accordingly using the code first approach. But the problem is, I am able to save the document without assigning the UserID foreign key id in the Documents table . What am I missing here? Below is my novice attempt. ApplicationUser Model: it's the standard model provided by the framework. Document Model: public class Document { public int Id { get; set;

Migration does not alter my table

倾然丶 夕夏残阳落幕 提交于 2019-12-18 09:30:06
问题 I just enabled migrations in my project and added a few fields to UserProfile : [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string Email { get; set; } public string Description { get; set;} public DateTime? CreatedOn { get; set; } public DateTime? LastAccess { get; set; } } I Add-migration AddFieldsForUserProfile and it created: ... public

Getting 'Context is not constructible. Add a default constructor or provide an implementation of IDbContextFactory."

ぐ巨炮叔叔 提交于 2019-12-18 07:35:02
问题 I am getting this error when I try to use code first migrations. My context has a constructor with the connection name. public class VeraContext : DbContext, IDbContext { public VeraContext(string NameOrConnectionStringName = "VeraDB") : base(NameOrConnectionStringName) { } public IDbSet<User> Users { get; set; } public IDbSet<Product> Products { get; set; } public IDbSet<IntCat> IntCats { get; set; } } This connection name is injected with ninject when the project runs, I have also specified

Getting 'Context is not constructible. Add a default constructor or provide an implementation of IDbContextFactory."

末鹿安然 提交于 2019-12-18 07:34:20
问题 I am getting this error when I try to use code first migrations. My context has a constructor with the connection name. public class VeraContext : DbContext, IDbContext { public VeraContext(string NameOrConnectionStringName = "VeraDB") : base(NameOrConnectionStringName) { } public IDbSet<User> Users { get; set; } public IDbSet<Product> Products { get; set; } public IDbSet<IntCat> IntCats { get; set; } } This connection name is injected with ninject when the project runs, I have also specified

How do I add an additional column to the __MigrationHistory table?

随声附和 提交于 2019-12-18 07:03:32
问题 Per Customizing the Migrations History Table, I should be able to add a column, however I'm not able to find any examples on how to actually add the new column. I'm mostly confused about where to put the actual property and how to configure it to the existing __MigrationHistory table. From the documentation, I can customize the table configuration like so.. protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<HistoryRow

How can I disable the use of the __MigrationHistory table in Entity Framework 4.3 Code First?

扶醉桌前 提交于 2019-12-18 04:45:45
问题 I'm using Entity Framework 4.3 Code First with a custom database initializer like this: public class MyContext : DbContext { public MyContext() { Database.SetInitializer(new MyContextInitializer()); } } public class MyContextInitializer : CreateDatabaseIfNotExists<MyContext> { protected override void Seed(MyContext context) { // Add defaults to certain tables in the database base.Seed(context); } } Whenever my model changes, I edit my POCO's and mappings manually and I update my database