Private/Cs/ModelProj/New-ContextWithViewCsToString.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
}