Entity Framework Core - Shadow Properties

One of the newest features in Entity Framework Core is Shadow Properties. Shadow Properties are fields which are not part of your entity class but exist only in the entity model. In this post, let’s figure out how to use shadow properties in Entity Framework Core and why they can be useful.

The first nuance that you will run into with Entity Framework is that EF will always ask for an ID field in each entity model. What do you do if you have a 3rd party extension and want to create and entity against their class dynamically?

Below is an example context that will do this. Override the OnModelCreating function of your Context. Run a for loop over each entity type. Notice by convention you can just add a field called “id” and Entity Framework Core will automatically create an id field with a primary key. This can save a bunch of time when you need to generate extras fields. After running this you will notice Class1 and Class2 will both have Id and SecondField added to their entity model.

public class ShadowContext : DbContext {

    public DbSet<Class1> Class1 { get; set; }
    public DbSet<Class2> Class2 { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
        foreach (var entityType in modelBuilder.Model.GetEntityTypes())


Interchange Control Header

Interchange Control Header - ISA Segment

ISA*00*          *00*          *ZZ*8008675309     *01*800123456      *180101*0800*^*00501*000001234*0*P*>

The purpose of this segment is to identify the sender and receiver. Also it identifies date, time and control number information.

ISA-01 through ISA-04: In the example above, ISA-01 through ISA-04 are not being used. These elements are rarely used anymore. That is why they are 00 and null. They used to be used for authorization in the past.

ISA-05 and ISA-06: These segments represent the sender qualifier and the sender ID. In the data segment above ISA-05 has a qualifier of ZZ. This example qualifier means the SenderID will follow. ISA-06 has the actual ID.

ISA-07 and ISA-08: These segments represent the receiver qualifier and the receiver ID. In the example above ISA-07 has a qualifier of 01. This qualifier means the ReceiverID will follow.

ISA-09 and ISA-10: ISA-09 is the interchange date in YYMMDD format. ISA-10 is the time in HHMM format. This transmission was sent on January, 1st 2018 at 08:00

ISA-11: is a repetition separator. It is used to separate repeated occurrences of a simple data element or a composite data structure. For example, a pipe character (I).

ISA-12: This is the EDI standard published version number. In the example above it is 00501;

ISA-13: This is a 9 digit control number used for tracking purposes. This number must match IEA-02 (Interchange Envelope Trailer). This number should be unique. The number should not be re-used for at least 3 years. If this number doesn’t match the file will be not be allowed through the payers system.

ISA-14: This is used mainly for reporting the status of processing a received interchange header and trailer or the non-delivery by a network provider. Usually this will be set to ‘0’ value. However, some payers send these back as part of their acknowledgement process. The payers companion guide will indicate if the TA1 is being used or not.

ISA-15: This indicates whether data enclosed by this interchange envelope is test ‘T’, production ‘P’ or information ‘I’. In the example above it is ‘P’ Note: Make sure to reference your companion document in the state your working on. Some states including Texas want this value to always be a P.

ISA-16: This field provides the delimiter. It is used to separate component data elements within a composite data structure. The value must be different than the data element separator and the segment terminator

Structure of X12 Envelopes

Structure of X12 Envelopes

  • Interchange Envelope

  • Functional Group

  • Transaction Set

The structure of a X12 envelopes is shown below. Each of these levels is explained at a basic level detail in the remainder of this section.


Header Segments

The Header is made up of the following 3 segments: the ISA, GS and ST segments.

The ISA segment identifies the sender and receiver of the EDI transmission. The ISA is used to begin an Interchange of one or more GS segments, also known as Functional Groups.

The GS segment identifies the application type for the interchange for both sender and receiver. This segment can be used to route EDI data to various systems or locations by trading partners. The GS segment is also the beginning of a functional group. This segment is also used to provide control information.

The ST segment identifies the type of document you are sending or receiving during EDI transmission. This segment is the beginning of the document, or transaction set.

Trailer Segments

The Trailer Segment is made up of the following 3 segments: the SE, GE and IEA segment.

The SE segment identifies the end of the document or transaction. This segment will display a total quantity of Data Segments sent including the ST and SE segments. This quantity can be used to verify all EDI data transmitted was received by the trading partner.

The GE segment indicates the end of the data provided under a GS segment, or functional group. Multiple GS segments can be included in an EDI transmission, so this segment can indicate the end of a document type or application type.

The IEA segment is the last segment sent or received in an EDI transmission. The IEA indicates this is the end of the current EDI file.

Control Numbers

Control Numbers are included in all header and trailer segments as an additional way of tracking EDI files. Control numbers displayed in the header segments must match control numbers displayed in the trailer segments. The ISA/IEA control numbers must match. The GS/GE control numbers must match, and the ST/SE control numbers must match. If these numbers don’t match the payer may reject your file. Control numbers are created when generating your EDI files.

Configuring Let's Encrypt SSL Certificates on Azure.

Today we are going to configure Let’s Encrypt SSL Certificates on Azure using the Webapp renewer extension. This extension makes it a lot easier to configure multiple Azure websites at the same time.

Here is a link to the original site extension. You can read through all the benifits here: https://github.com/ohadschn/letsencrypt-webapp-renewer. To get this to work I had to modify the steps slightly. The major key is to make sure your web config allows your Website app to serve extensionless pages. (More on that later).

1) Create a new Web App that you can run this extension from.

Click Create a Resource and give your web app a name (Make sure to put all your resources in the same Resource Group):


All of the configuration settings for this site extension are going to be stored in the Web App Application Settings section. This is where the extension will pull the info it needs to generate the certificates for each site. This works great if you have multiple sites to certify. We will set this up later right before the Web Job is set up.

2) Create a Service Principal

A service principal is a Azure AD entry that can be used for unattended access to Azure resources. You can consider it service account. You need a service principal with Access to your Resource Group(s) in order for the Let's Encrypt site extension to renew your certificate without manual involvement once they expire. The service principal is also used to install the certificate the first time, in order to validate that it is setup correctly. This is probably the most difficult part of the setup.

a) Select Active Directory

b) Select New Application Registration

c) Give the App Registration a Name : Letsencrypt / Application Type: Web app / API : Sign on URL https://letsencrypapp.azurewebsites.net (same name as the web app you just created)

d) Create a client secret. Click on the All settings and click Keys to setup a new key for your application (the service principal password).

e) Give the new key a description, select a duration and hit Save, after saving the client secret will show up in the value column. Save that for later, You will not be able to retrieve the key later so you will want to copy it now.

3) Grant permissions to the Service Principal

a) In the portal find the resource group for your App Service and App Service plan, click the Access button.

b) Click Add, and select the Role Contributor

c) Now add the service principal user you created earlier to the role, you can find the service principal by searching for the Application Name you used in step 7 of creating the Service Principal.  (Note: you have to do a search otherwise you wont find the User).

4) Configuration

Refer to the Configuration Settings here for the webapp: https://github.com/ohadschn/letsencrypt-webapp-renewer

5) Download the WebJob zip file

a) Goto the web application and select WebJobs Add +. Upload the zip file you just downloaded. Set the type to triggered and the CRON expression to 0 0 0 1 1,3,5,7,9,11 * .

b) Important: Add this line to your webconfig in your root level directory. I couldn’t get this to work without this setting.




<clear />

<rule name="LetsEncrypt Rule" stopProcessing="true">

<match url="^\.well-known.*$" />

<action type="None" />





Congratulations you have SSL certificates working on all your web apps.

Javascript Module Pattern

Well you've made it this far. Welcome back. Here's how to reuse your C# skills and start structuring your JavaScript in a much more object orientated fashion.

The Module pattern will greatly help you keep code organized especially when dealing with larger and more complex user interfaces.

Creating a Module

To understand what a Module in JavaScript is, you'll need to visualize how the following concept works:

(function () {
  // code

This is known as a IIFE or Immediately-Invoked-Function-Expressions, basically meaning this function runs as soon as it's defined. The idea here is to return only the properties we need access to in the global scope.

After creating this new scope, we need to namespace our code so that we can access any methods we return. Let's create a namespace for our Module.

var Module = (function () {
  // code

We now have Module declared in the browsers global scope, which means we can call it wherever we like, and even pass it into another Module.

Private Methods

JavaScript doesn't have private functions or variables built in, but we can create a new scope within this namespace that emulates these concepts.

One of the most benifical features of coding like this is avoiding naming collisions. Especially if your writing monolithic Single Page Applications you need a way to define namespaces.

var Module = (function () {
var privateMethod = function () {
// do something


The above example declares a function called privateMethod, which is locally declared inside the new scope. This function can't be accessed anywhere except inside of the Modules scope.

Public Methods

Typical Modules will use return and return an Object to the Module, to which the methods bound to the Object will be accessible from the Module’s namespace. A real basic example of returning an Object with a function as a property:

var Module = (function () {
    return {
        publicMethod: function () {
            // code


As we're returning an Object Literal, we can call them exactly like Object Literals:


Are you seeing some object orientated programming like similaties?

This style can really help you when the code starts getting complex.

Performance considerations

It is not ideal to unnecessarily create functions within other functions if closures are not needed for a particular task, as it will negatively affect script performance both in terms of processing speed and memory consumption.

For instance, when creating a new object/class, methods should normally be associated to the object's prototype rather than defined into the object constructor. The reason is that whenever the constructor is called, the methods would get reassigned (that is, for every object creation).

var Module = (function () {

    function Module() {}

    var privateMethod = function () {
        return "Hello World";

    TimeEntry.prototype.publicMethod = function () {
        //call private method

    return Module;


Now you could type something like Module.publicMethod() and you would see an alert saying Hello World.

If your looking for ultimate customization abilities, code organazation and performance, utilizing the JavaScript Module Pattern is not a bad path to take.

Thanks for reading and keep it real! Hope to see you next time.

Javascript Closures

A closure is an inner JavaScript function that has access to the outer (enclosing) function's variables—scope. A closure has three scopes which 1) has access to its own scope (variables defined between its curly brackets) 2) has access to the outer function's variables and 3) has access to the global variables.

A basic example of a JavaScript closure:

function showMessage(message) {
   var x = "Hello ";

   // this inner function has access to the outer function's variables, including the parameter
   function showEntireMessage() {
       return x + " " + message;

   return showEntireMessage();

showMessage("World"); // Hello World

Closures are useful because they let you associate some data with a function that operates on that data. This has obvious parallels to object oriented programming, where objects allow us to associate some data (the object's properties) with one or more methods. Consequently, you can use a closure anywhere that you might normally use an object with only a single method. Situations where you might want to do this are particularly common on the web. Much of the code we write in front-end JavaScript is event-based — we define some behavior, then attach it to an event that is triggered by the user (such as a click or a keypress).

Closures store references to the outer function's variables, they do not store the actual value. Closures get more interesting when the value of the outer function's variable changes before the closure is called. This is an important feature, such as this private variables example:

function productId () {
    var productId = 123;
    // We are returning an object with some inner functions
    // All the inner functions have access to the outer function's variables
    return {
        getID: function ()  {
            // This inner function will return the UPDATED productId variable
            // It will return the current value of productId, even after the productId function changes it
            return productId;  
        setID: function (theNewId)  {
            // This inner function will change the outer function's variable anytime
            productId = theNewId;                                                                 

var pId = productId(); // At this juncture, the productId's outer function has returned.
pId.getId(); // 123
pId.setId(456); // Changes the outer function's variable
pId.getId(); // 456: This returns the updated productId's variable

Some caveats

Prior to the introduction of the let keyword in ECMAScript 2015, a common problem with closures occurred when they were created inside a loop. So if you must use a for loop make sure your clients are running IE9+ and make use of the let keyword as shown in the example below.

function showHelp(help) {
    document.getElementById('help').innerHTML = help;

function setupHelp() {
    var helpText = [
      {'id': 'email', 'help': 'Your e-mail address'},
      {'id': 'name', 'help': 'Your full name'}

  for (var i = 0; i < helpText.length; i++) {
    let item = helpText[i];
    document.getElementById(item.id).onfocus = function() {


Note: The example above uses let instead of var, so every closure binds the block-scoped variable, meaning that no additional closures are required.

Intro to Vue.Js

VueJs is a relatively new MVVM javascript framework designed for building interactive web interfaces. Here is a feature comparison to other popular frameworks on their website: Vue comparison

This tutorial aims to give you an overview of some of the basic features of Vue. In future sessions we\'ll be looking at some more advanced topics and how it could be possible to build large applications with Vue.

Creating a Vue Instance with new Vue()

Let's start off by creating a basic HTML page and importing VueJs.

<!DOCTYPE html>      
  <title>Intro to VueJs - Livesoftware</title>
 <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.3/vue.js'></script>

We can now create a div tag with an id of app and a new Vue instance. When you create a new Vue instance using the Vue() constructor (mapped to id app) Vue's scope will only know about the elements that are declared within this div but nothing about what exists outside this div element.

You can specify the mounting point of a Vue instance using the el option in the Vue() constructor which accepts and argument of the DOM element id you wish to mount your Vue instance:

<!DOCTYPE html>      
  <title>Intro to VueJs - Livesoftware</title>
   <div id='app'>
     <!-- app will be the DOM element that VueJs mounts to -->
 <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.3/vue.js'></script>
    // bind a VueJs instance to the div with the id of app
    var vm = new Vue({
      el: '#app'

Above we created a Vue instance using the Vue() constructor which accepts an option object (much like a constructor in C#) that specifies the element to mount on.

Now that we have created a Vue instance and connected it to a DOM element, Vue is aware of any element inside of this instance.

Data Binding with Vue v-model

To demonstrate the data binding features of Vue, we can create a HTML text input with the v-model directive that can be used to dynamically update the message property in the data object.

The v-models directive is similar to any other HTML attribute. This creates a 2-way data binding on any form input elements including input, textarea, and select. The value of the v-model directive is the data we wish to update on user input events. For this particular example, we are binding the input element to the message string that we have created in the Vue data object as shown below:

<div id='app'>
  <!-- app will be the DOM element that VueJs mounts to -->
  Enter a message: <input type='text' v-model='message'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.3/vue.js'></script>
  // bind a VueJs instance to the div with the id of app
  var vm = new Vue({
    el: '#app',
    data: {
      message: 'Hello World'

Running the code above will display a textbox similar to below.

Enter a message:

Hello World

Now type something different into the textbox and open chome dev tools. You should see the viewmodels message value will be mapped to whatever is entered in the textbox.

This tutorial has demonstrated some of the basic initialization and mapping ideas in Vue. In part 2 we will get into some more advanced functionality.