<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: OliBlade</title>
    <description>The latest articles on DEV Community by OliBlade (@oliblade).</description>
    <link>https://dev.to/oliblade</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F496679%2Fd32114f8-ac0e-494c-a684-302ba845c974.png</url>
      <title>DEV Community: OliBlade</title>
      <link>https://dev.to/oliblade</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oliblade"/>
    <language>en</language>
    <item>
      <title>Deploying to Firebase with GitHub Actions</title>
      <dc:creator>OliBlade</dc:creator>
      <pubDate>Thu, 29 Oct 2020 19:42:35 +0000</pubDate>
      <link>https://dev.to/oliblade/deploying-to-firebase-with-github-actions-1on1</link>
      <guid>https://dev.to/oliblade/deploying-to-firebase-with-github-actions-1on1</guid>
      <description>&lt;p&gt;This is a quick guide on how to get an un-hosted project, onto &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;Firebase&lt;/a&gt; hosting using &lt;a href="https://docs.github.com/en/free-pro-team@latest/actions" rel="noopener noreferrer"&gt;GitHub Actions&lt;/a&gt; which is updated on every merge. We’ll just be using the Firebase CLI, no fancy coding required!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2A9ixlX2uq9cVQif4Y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2A9ixlX2uq9cVQif4Y.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few assumptions before we begin:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A repository on GitHub with a website ready to host (In my case, a fresh Angular App “ng new”)&lt;/li&gt;
&lt;li&gt;A Firebase account&lt;/li&gt;
&lt;li&gt;The latest &lt;a href="https://www.npmjs.com/package/firebase-tools" rel="noopener noreferrer"&gt;Firebase cli&lt;/a&gt; installed and ready to go&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  So let’s get started
&lt;/h3&gt;

&lt;p&gt;First up, head over to &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;Firebase&lt;/a&gt; and create your new Project. Just follow the basic steps, add your project name, enable analytics if you want to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AgnXqWAkLMXMYULQl0I0M6Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AgnXqWAkLMXMYULQl0I0M6Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s hop into our command window and setup the Firebase and GitHub stuff.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get a command window open in your project directory.&lt;/li&gt;
&lt;li&gt;Type the following command.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase init hosting:github
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will walk you through the process from start to finish&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Follow the steps in the console, use the existing Firebase project you made earlier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When prompted for the GitHub repository, type in the following “Username/Repository”, or in my case&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OliBlade/MyFirebaseApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;You’ll also be asked to input the build directory of your site, and your build command, in my case “npm run build”&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Once that’s all done
&lt;/h3&gt;

&lt;p&gt;You’ll have seen in the output that this has created a service account in your Firebase project with permission to deploy Firebase Hosting. Also that service account’s JSON key has been uploaded to the GitHub repository as a &lt;a href="https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets" rel="noopener noreferrer"&gt;GitHub Secret&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In your files you’ll notice a folder called “.github” with a couple of YAML files in the workflows folder. If you take a look at these you will see how they reference the newly created secret and configure the &lt;a href="https://github.com/marketplace/actions/deploy-to-firebase-hosting" rel="noopener noreferrer"&gt;GitHub Action&lt;/a&gt; to deploy Firebase Hosting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F687%2F1%2A688WrTCulz4CvkCTvV5kcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F687%2F1%2A688WrTCulz4CvkCTvV5kcg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Commit and Push
&lt;/h3&gt;

&lt;p&gt;It doesn’t really matter if you do this on a new branch or not, but you probably should. Navigate to your repository and click the Actions tab. You will see your action executing and building the project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F740%2F1%2A-arD2VC9Q5xc9zxkPDB7Og.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F740%2F1%2A-arD2VC9Q5xc9zxkPDB7Og.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice step 4 deploys to FireBase, if you check out your new project in &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;Firebase Console&lt;/a&gt; you will see a freshly deployed and hosted app.&lt;/p&gt;

&lt;p&gt;This now updates your live FireBase hosted website with every merge into your main branch, and every PR in this GitHub repo will get its own preview URL!&lt;/p&gt;

&lt;h3&gt;
  
  
  Some extra reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This post was heavily based on &lt;a href="https://firebase.google.com/docs/hosting/github-integration" rel="noopener noreferrer"&gt;this Firebase documentation&lt;/a&gt;, but I thought I’d do a little walkthrough&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets" rel="noopener noreferrer"&gt;GitHub Secrets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/free-pro-team@latest/actions" rel="noopener noreferrer"&gt;GitHub Action&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/marketplace/actions/deploy-to-firebase-hosting" rel="noopener noreferrer"&gt;GitHub Action to deploy to Firebase hosting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>githubactions</category>
      <category>github</category>
      <category>firebase</category>
    </item>
    <item>
      <title>Prerender your Angular app, as simple as possible</title>
      <dc:creator>OliBlade</dc:creator>
      <pubDate>Mon, 12 Oct 2020 17:22:27 +0000</pubDate>
      <link>https://dev.to/oliblade/prerender-your-angular-app-as-simple-as-possible-3638</link>
      <guid>https://dev.to/oliblade/prerender-your-angular-app-as-simple-as-possible-3638</guid>
      <description>&lt;p&gt;Have you ever wanted a simple static site, but you won’t want to lose Angular in the process? Here’s how you do it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C6u9HwYy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/738/0%2AdmYfFJBn25tHGnBi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C6u9HwYy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/738/0%2AdmYfFJBn25tHGnBi.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting started
&lt;/h3&gt;

&lt;p&gt;Make sure your Angular CLI and Angular version is up to date, you can check with ng version, and update with ng update. Version 9+ should do it&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uJLndogY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/531/1%2Ag048cC98wu9yDfjB7L4PcA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uJLndogY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/531/1%2Ag048cC98wu9yDfjB7L4PcA.png" alt=""&gt;&lt;/a&gt;My Angular version&lt;/p&gt;

&lt;h3&gt;
  
  
  From start to finish
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Start a new Angular Project using the CLI with ng new&lt;/li&gt;
&lt;li&gt;Install Angular Universal Express Engine using the CLI ng add @nguniversal/express-engine&lt;/li&gt;
&lt;li&gt;Add the routes you would like to prerender to the “prerender” -&amp;gt; “routes” array in the angular.json&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1rQqBKYo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/528/1%2A0N6FLEvc8YaX7OpJtxLfLA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1rQqBKYo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/528/1%2A0N6FLEvc8YaX7OpJtxLfLA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Prerender the content with npm run prerender . This will generate the prerendered files in “dist” -&amp;gt; MyApp -&amp;gt; “browser”. Note how you have “index.html” with the prerendered content and “index.original.html” with the original copy&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QnaiMQVd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/634/1%2ABRhpiYkZqKVriVcDzjPstg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QnaiMQVd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/634/1%2ABRhpiYkZqKVriVcDzjPstg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that’s it... Bob is indeed my uncle.&lt;/p&gt;

</description>
      <category>prerender</category>
      <category>angularuniversal</category>
      <category>angular</category>
    </item>
    <item>
      <title>Entity Framework Core — From zero to something</title>
      <dc:creator>OliBlade</dc:creator>
      <pubDate>Wed, 30 Sep 2020 16:04:54 +0000</pubDate>
      <link>https://dev.to/oliblade/entity-framework-core-from-zero-to-something-5e3o</link>
      <guid>https://dev.to/oliblade/entity-framework-core-from-zero-to-something-5e3o</guid>
      <description>&lt;h3&gt;
  
  
  Entity Framework Core — From zero to something
&lt;/h3&gt;

&lt;p&gt;I… have never used Entity Framework before. But when someone pitched me the idea of removing all my CRUD stored procedures I jumped right in with my new ASP.NET Core 3.1 project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BM1zWboo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/591/1%2Adp1DGgXapJV47j3NgtnLRw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BM1zWboo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/591/1%2Adp1DGgXapJV47j3NgtnLRw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting started
&lt;/h3&gt;

&lt;p&gt;To begin with, I created a SQL Server Database Project in Visual Studio with a couple of tables that reference each other so we have something to play with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE [dbo].[Campaigns]
(
 [CampaignId] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
 [Name] NVARCHAR(100),
 [Enabled] BIT, 
 [UserId] NVARCHAR(450) NOT NULL
)

CREATE TABLE [dbo].[CampaignFilters]
(
 [CampaignFilterId] INT NOT NULL PRIMARY KEY IDENTITY, 
 [CampaignId] UNIQUEIDENTIFIER NOT NULL,
 [FilterTypeId] INT NOT NULL

CONSTRAINT [FK_CampaignFilters_Campaigns] FOREIGN KEY ([CampaignId]) REFERENCES [Campaigns]([CampaignId])
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I used the Schema Compare feature in Visual Studio to add my tables to my Database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--njsqa8zI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/331/1%2AHJRD37NzAUTSOJ9qgRE7DQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--njsqa8zI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/331/1%2AHJRD37NzAUTSOJ9qgRE7DQ.png" alt=""&gt;&lt;/a&gt;Database in SSMS&lt;/p&gt;

&lt;p&gt;With my new tables safely in SQL Server it was time to move on to some Entity Framework things.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generating the models
&lt;/h3&gt;

&lt;p&gt;Easy as 1…2…3&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the command in Visual Studio Package Manager Console to scaffold the models and Model Context (the thing that tells the models what they are)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scaffold-DbContext ”Server=localhost;Database=EntityFrameworkDB;User Id=DBUser;Password=Password;” -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/Database -force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Realise the scaffolded models have weird pluralisation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8bie9qCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/217/1%2AZFsUwcd5oNv5kNyQI1nWdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8bie9qCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/217/1%2AZFsUwcd5oNv5kNyQI1nWdw.png" alt=""&gt;&lt;/a&gt;Why is it plural? Maybe it’s just me :(&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the following Nuget package and try again&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5xEG3TLc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/974/1%2ADT-kcgQsy7tZTWiffb_oRw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5xEG3TLc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/974/1%2ADT-kcgQsy7tZTWiffb_oRw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KxiPds2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/218/1%2AuKP-atMROdzOiaalSJdXjg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KxiPds2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/218/1%2AuKP-atMROdzOiaalSJdXjg.png" alt=""&gt;&lt;/a&gt;Successful scaffolding&lt;/p&gt;

&lt;h3&gt;
  
  
  Trying it out
&lt;/h3&gt;

&lt;p&gt;I slapped together a couple of CRUD-y read and writes using the models and context I had just made using some dependency injection to get hold of the DBContext.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CampaignRepository
 {
  private EntityFrameworkDBContext EntityFrameworkDBContext { get; }

public CampaignRepository(EntityFrameworkDBContext entityFrameworkDBContext)
  {
   EntityFrameworkDBContext = entityFrameworkDBContext;
  }

public IEnumerable&amp;lt;Campaign&amp;gt; GetCampaignsByUser(string userID)
  {
   return EntityFrameworkDBContext.Campaigns.Where(x =&amp;gt; x.UserId == userID);
  }

public void SaveCampaign(Campaign campaign)
  {
   EntityFrameworkDBContext.Campaigns.Add(campaign);
   EntityFrameworkDBContext.SaveChanges();
  }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And sure enough…. it worked.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other things I learned along the way
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;You can run the scaffold command from the DotNet CLI.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet ef DbContext Scaffold “Server=localhost;Database=EntityFrameworkDB;User Id=DBUser;Password=Password;” Microsoft.EntityFrameworkCore.SqlServer -o Models/Database — force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You can use stored procedures along side Entity Framework, there’s no ish.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update and Add are not the same thing and will cause errors if used interchangeably.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the “-force” flag to overwrite your changes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can use partial classes to expand on the models&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>dotnetcore</category>
      <category>entityframeworkcore</category>
      <category>gettingstarted</category>
    </item>
  </channel>
</rss>
