Update ContextModelSnapshot EF Core

You can execute the command Add-migration temporary to create a new empty migration. Then, run Remove-Migration temporary (or their dotnet-cli counterparts) In recent editions of EF Core (3+), just use: Remove-Migration (will revert the last migration) It will create model snapshot from scratch even if the migration has already been deleted. This approach works perfectly … Read more

ASP.NET Core MVC controllers in separate assembly

Still an issue in ASP.Net Core 1.0, not sure if it’s by design now. Easiest solution is to do this in Startup.cs/ConfigureServices services.AddMvc() .AddApplicationPart(typeof(<class in external assembly>).Assembly) .AddControllersAsServices(); AddApplicationPart explicitly includes the assembly in searches for controllers. The call to AddControllersAsServices() will add all the discovered controllers into the services collection, and if you put … Read more

MVC 6 HttpPostedFileBase?

MVC 6 used another mechanism to upload files. You can get more examples on GitHub or other sources. Just use IFormFile as a parameter of your action or a collection of files or IFormFileCollection if you want upload few files in the same time: public async Task<IActionResult> UploadSingle(IFormFile file) { FileDetails fileDetails; using (var reader … Read more

ASP.NET Core—access Configuration from static class

A slightly shorter version based on the same principle as above… public Startup(IConfiguration configuration) { Configuration = configuration; StaticConfig = configuration; } public static IConfiguration StaticConfig { get; private set; } To use in another static class: string connString = Startup.StaticConfig.GetConnectionString(“DefaultConnection”);

Include several references on the second level

.ThenInclude() will chain off of either the last .ThenInclude() or the last .Include() (whichever is more recent) to pull in multiple levels. To include multiple siblings at the same level, just use another .Include() chain. Formatting the code right can drastically improve readability. _dbSet .Include(tiers => tiers.Contacts).ThenInclude(contact => contact.Titre) .Include(tiers => tiers.Contacts).ThenInclude(contact => contact.TypeContact) .Include(tiers … Read more