ef-migrations

How should I model friendships between users with EF code first?

老子叫甜甜 提交于 2019-12-01 20:29:00
问题 I'm tring to figure out how to represent friendships between users with Entity Framework (5) Code First. My initial idea was to create a class Friendship which contains references to two User instances, so that friendships are represented by separate objects. public class Friendship { public virtual int Id { get; set; } [Required] public virtual UserProfile User1 { get; set; } [Required] public virtual UserProfile User2 { get; set; } [Required] public virtual DateTime Since { get; set; } }

How should I model friendships between users with EF code first?

走远了吗. 提交于 2019-12-01 18:55:24
I'm tring to figure out how to represent friendships between users with Entity Framework (5) Code First. My initial idea was to create a class Friendship which contains references to two User instances, so that friendships are represented by separate objects. public class Friendship { public virtual int Id { get; set; } [Required] public virtual UserProfile User1 { get; set; } [Required] public virtual UserProfile User2 { get; set; } [Required] public virtual DateTime Since { get; set; } } [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute

Performing an IDENTITY_INSERT using EF5 Code First Migrations

夙愿已清 提交于 2019-12-01 16:56:28
I have a POCO that I am trying to create via Code First Migrations and then seed data. The problem is that I want to insert specific values into the identity column when seeding. Here is my POCO public class Result { public long ResultId { get; set; } public long? TeamId { get; set; } public Team Team { get; set; } } And here is my AddOrUpdate call in the Seed method of the Configuration.cs context.Results.AddOrUpdate ( r => r.ResultId, new Result { ResultId = 101, TeamId = null }, new Result { ResultId = 201, TeamId = null } ); As expected, it does not insert the values of 101 and 201, but

How to drop a table in Entity Framework Code First?

前提是你 提交于 2019-12-01 16:47:25
I am using Entity Framework with Auto Migrations. So when I add a new model to my Context, my database is updated and new table is created. What I want to do is the opposite, droping the table completely from database. However, removing the definition from Context class does not work. public class CompanyContext : DbContext { public DbSet<Permission> Permissions { get; set; } public DbSet<Company> Companies { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } } For instance, I want to remove Company table from database. To

Can't add Entity Framework Core migrations to .NET Standard 2.0 project

☆樱花仙子☆ 提交于 2019-12-01 10:16:02
问题 I've got a Solution with many projects. One of them ( Domain ) is a .NET Standard 2.0 project where I made my EF Core DbContext implementation for which I want to enable database migrations . I saw various blogs and Q/A forums where the problem was explained but none of the proposed solutions seem to work for me because of the .NET Core newer version or (probably) for my particular solution configuration. Solution projects Engine (.NET Core 2.1 Console App) Web API (.NET Core 2.1 Library)

ASP.NET MVC 5 Identity userManager.IsInRole

瘦欲@ 提交于 2019-12-01 08:41:51
The following code does not work, and I can't explain why... My user manager is causing significant distress in that it creates users and roles just fine but when I run this code userManager.IsInRole is always returning false, so the second time I run my seed I am hitting errors because it is trying to create the record despite the fact it already exists! Please note that this is occurring when I am running update-database against my migrations project, is the fact this is a non ASP project causing issues, if so why? shouldn't an error be thrown. This is the first project I have used Identity

ASP.NET MVC 5 Identity userManager.IsInRole

情到浓时终转凉″ 提交于 2019-12-01 06:03:46
问题 The following code does not work, and I can't explain why... My user manager is causing significant distress in that it creates users and roles just fine but when I run this code userManager.IsInRole is always returning false, so the second time I run my seed I am hitting errors because it is trying to create the record despite the fact it already exists! Please note that this is occurring when I am running update-database against my migrations project, is the fact this is a non ASP project

Unable to update database to match the current model because there are pending changes and automatic migration is disabled

断了今生、忘了曾经 提交于 2019-12-01 05:54:26
I, for the life of me, can't get rid of this error message. I have tried almost everything that I can. MyDBContext.cs public MyDBContext() : base("ConnStr_Dev") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDBContext, DbMigrationsConfiguration<MyDBContext>>()); //Database.SetInitializer<MyDBContext>(null); base.OnModelCreating(modelBuilder); } GenericRepository.cs public void Insert(T obj) { table.Add(obj); //this is where it throws the error, inserting first time. } Tried all of these in different

Visual Studio Component Cache Out of Date

橙三吉。 提交于 2019-12-01 05:10:58
问题 Almost every time I try to run the update-database command for EF migrations, I get the following error in Visual Studio 2015: Exception calling "GetService" with "1" argument(s): "Exception calling "Invoke" with "2" argument(s): "The Visual Studio component cache is out of date. Please restart Visual Studio. The Visual Studio component cache is out of date. Please restart Visual Studio."" At D:\Dev\Project\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:1004 char:5 +

Error : The EntityFramework package is not installed on project

爷,独闯天下 提交于 2019-12-01 04:44:11
I've just installed SQL Server 2008, configured my ASP.NET MVC 4 project to be deployed at Local IIS and have added a new connection to a database which have been created at time (in sql server 2008). When I try to enable migrations (Entity Framework) via Enable-Migrations -ContextTypeName MonitoringNDataContext from Package Manager Console . I got this following error : The EntityFramework package is not installed on project 'MonitoringN.Tests'. Any brilliant idea, please ? MonitoringN : Name the ASP.NET MVC 4 project. MonitoringNDataContext : Name of my DBContext class which is placed into