Private/Cs/ModelProj/New-ContextWithViewCsToString.ps1
Function New-ContextWithViewCsToString([string]$modelNamespace, [string]$modelWithViewNamespace, [string]$contextName, [string]$contextWithViewName ) { [string]$result = @" using System; using System.Collections.Generic; using System.Text; using $($modelNamespace); using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace $($modelWithViewNamespace) { /* * $contextName is the regular Entity Framework * data model generated by the dotnet entity framework * scaffolding tool. $contextWithViewName is a subclass * that also contains database views (because scaffolding * can't script views yet). Always use this context instead * since it has tables and views. */ public partial class $contextWithViewName : $contextName { // VIRTUAL_DB_SET_ABOVE_HERE Leave this comment for BoxTurtlePs code builder to use public $contextWithViewName(DbContextOptions options) :base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // For each view you need to provide a primary key // EntityFramework core doesn't like views so we have to fake it manually // MODEL_BUILD_ENTITY_ABOVE_HERE Leave this comment for BoxTurtlePs code builder to use } } } "@ return $result } |