Unique Key constraints for multiple columns in Entity Framework

With Entity Framework 6.1, you can now do this: [Index(“IX_FirstAndSecond”, 1, IsUnique = true)] public int FirstColumn { get; set; } [Index(“IX_FirstAndSecond”, 2, IsUnique = true)] public int SecondColumn { get; set; } The second parameter in the attribute is where you can specify the order of the columns in the index. More information: MSDN

The relationship could not be changed because one or more of the foreign-key properties is non-nullable

You should delete old child items thisParent.ChildItems one by one manually. Entity Framework doesn’t do that for you. It finally cannot decide what you want to do with the old child items – if you want to throw them away or if you want to keep and assign them to other parent entities. You must … Read more

Reset Entity-Framework Migrations

You need to : Delete the state: Delete the migrations folder in your project; And Delete the __MigrationHistory table in your database (may be under system tables); Then Run the following command in the Package Manager Console: Enable-Migrations -EnableAutomaticMigrations -Force Use with or without -EnableAutomaticMigrations And finally, you can run: Add-Migration Initial

What’s the difference(s) between .ToList(), .AsEnumerable(), AsQueryable()?

There is a lot to say about this. Let me focus on AsEnumerable and AsQueryable and mention ToList() along the way. What do these methods do? AsEnumerable and AsQueryable cast or convert to IEnumerable or IQueryable, respectively. I say cast or convert with a reason: When the source object already implements the target interface, the … Read more

EF Core Second level ThenInclude missworks

This is a known Intellisense issue with the ThenInclude overload for collection type navigation properties, tracked by the Completion missing members of lambda parameter in fault tolerance case #8237 Roslyn GitHub issue. Until it gets fixed, simply type the name of the property and it will compile successfully and work as expected. .ThenInclude(mu => mu.ParseSubTrees) … Read more

Entity Framework: One Database, Multiple DbContexts. Is this a bad idea? [closed]

You can have multiple contexts for single database. It can be useful for example if your database contains multiple database schemas and you want to handle each of them as separate self contained area. The problem is when you want to use code first to create your database – only single context in your application … Read more