How to create multiple dbcontext in entity framework

Creating Multiple DbContext in EntityFramework Is it possible to have multiple dbcontext? Yes, we can create multiple DbContext classes in EF, which you can see below. Syntax: Enable-Migrations -ContextTypeName<DbContext-Name-with-Namespaces> -MigrationsDirectory:<Migrations-Directory-Name> Add-Migration -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> <Migrations-Name> Update-Database -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> -Verbose Sample: Enable-migrations -ContextTypeName Migrations.DbContexts.Configuration -MigrationsDirectory:DbContexts Add-Migration -configuration Migrations.DbContexts.Configuration Update-Database -configuration Migrations.DbContexts.Configuration -Verbose

Continue reading


What is alternative to yield of laravel blade in asp.net razor

Asp.net razor equivalent to yield in laravel blade template // This is one modal of specifying a section in the content @Section mainHeader { } // This is another model, in this way the section is made as mandatory. @RenderSection(“mainHeader”) // Optional rendering of a section is below @RenderSection(“mainHeader”, required: false)

Continue reading


How to search by Date Range in Entity Framework

Date Range in Entity Framework If we want to search entity with date range, assume we are passing StartDate, and EndDate as Request.Params, in MM/dd/yyyy format. public ActionResult Search() { var StartDate = Request.Params[“StartDate”]; var EndDate = Request.Params[“EndDate”]; var visits = visitBAL.GetVisits(); if (StartDate != null && !StartDate.Equals(“”)) { visits = visits.Where(v => v.DateStart >= […]

Continue reading


Difference between Configuration.cs vs Database Initializer in Entity Framework

Difference between Configuration.cs vs Database Initializer in Entity Framework Configuration.cs file located inside Migrations folder, which will be created when we execute the command “Enable-Migrations” in Package Manager Console. We can make use of this class for seeding the datas into database. This class will seed the database whenever we execute the Update-Database command in […]

Continue reading


How to install entity framework

Entity Framework 6 Installation using vs2012 From the Tools menu click Library Package Manager and then click Package Manager Console. In the Package Manager Console window enter the following command: Install-Package EntityFramework Create the model classes Create the DatabaseContext class Create a folder called DAL inside project. This is the main class that communicates with database in entity framework using DBSet class […]

Continue reading