Learning ASP.NET Core: Scaffolding

After I made sure my migrations worked, I decided to make the database content editable straight away. I used Scaffolding to generate the basic layout for my edit / list and details pages. I’ll definitely make lots of changes to these, but they’ll work fine for now. So now I have a bunch of controllers and views to work with. I decided that tinyMce would do for now and added that through bower.

Since i made a class to hold standard page content, I changed the route in my home controller to load that content. It’s currently loaded through a GetPage() method in my home controller that takes the page slug as parameter.

The scaffolding feature is very powerful, and really speeds things up. I’m still not used to Razor however, so this will take time to get used to.


Posted in Uncategorized | Leave a comment

Learning ASP.NET Core: Migration trouble

I ran into my first little hick up when trying to run my migrations. in ASP.NET Core 1.1 you have to run this from the command line, or powershell. I tried from the command line.

dotnet ef migrations add "Basic setup"

I get a big red message saying No executable matching dotnet ef

Seems like I’m not the first one running into this, but I forgot to try the most obvious thing first.

I checked my csproj file, moved stuff around, tried several dotnet restores and dotnet builds from the command line. After a while I tried to run the command from a different directory. This time I used toe project dir, not the solution dir, and it worked right away.

When my migration was created I just ran dotnet ef database update

Everything looked ok, except I missed two tables. I realized I forgot to add them to the database context, but after I did that and made another migration everything worked fine.

I haven’t been writing much code yet, but already feed I’ve come quite far.

Next step will be to generate some views and controllers for database edits and start looking into dotnet.Identity.


Posted in Uncategorized | Leave a comment

Learning ASP.NET Core: MVC setup and creating the first models

I started out the other day by creating a new project with the standard MVC template.

I’ve decided to focus on functionality before doing layout, so I started by adding support for PostGreSQL through Entity framework core.

NOTE: For people trying to find information on ASP.NET Core. If you look at tutorials using version 1.0, they are referring to project.json. That file is no longer used, and all the package information must be placed in the .csproj file. To edit the .csproj file. Right clock your project in solution explorer.

The relevant parts of my  .csproj file looks like this right now.


<PackageReference Include=”Microsoft.ApplicationInsights.AspNetCore” Version=”2.0.0″ />
<PackageReference Include=”Microsoft.AspNetCore” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.AspNetCore.Identity.EntityFrameworkCore” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.AspNetCore.Mvc” Version=”1.1.3″ />
<PackageReference Include=”Microsoft.AspNetCore.StaticFiles” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.Extensions.Logging.Debug” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.VisualStudio.Web.BrowserLink” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.EntityFrameworkCore.Tools” Version=”1.1.1″ />
<PackageReference Include=”Microsoft.AspNetCore.Mvc.Razor” Version=”1.1.3″ />
<PackageReference Include=”Microsoft.AspNetCore.WebUtilities” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.EntityFrameworkCore.Design” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.Extensions.Logging.Debug” Version=”1.1.2″ />
<PackageReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”1.1.1″ />
<PackageReference Include=”Npgsql.EntityFrameworkCore.PostgreSQL” Version=”1.1.0″ />
<PackageReference Include=”Npgsql.EntityFrameworkCore.PostgreSQL.Design” Version=”1.1.0″ />
<DotNetCliToolReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Tools” Version=”1.0.1″ />
<DotNetCliToolReference Include=”Microsoft.EntityFrameworkCore.Tools.DotNet” Version=”1.0.0″ />

My editor is probably going to screw this code up, but at least you can see the packages.

Note that the Microsoft.EntityFrameworkCore.Tools.DotNet package has to be added manually. The newest version is not on NuGet and from what I can tell it won’t be added. You’ll need this if you want to run the dotnet ef stuff from the command line (see below).

I also added the identity packages to handle user authentication, but haven’t used it yet.

Since I don’t have a database yet, I decided to take a code first approach and build my tables from models. I won’t list all my entities here, but here’s the frist version of my article (post) class to use as an example.


public class Article
public int Id { get; set; }
public string ArticleSlug { get; set; }
public string ArticleTitle { get; set; }
public string ArticleKeywords { get; set; }
public string ArticleDescription { get; set; }
public string ArticleContent { get; set; }
public bool AllowComments { get; set; }
public DateTime LastUpdated { get; set; }
public DateTime PostedDate { get; set; }
public int CategoryId { get; set; }
public int ArticleType { get; set; }


Simple enough. Doing it this way, I could set up a bunch of entities faster than I would do it using a tool to edit the database directly.

When I had my models, I created my database context class.

I basically copied and pasted one from an example and made the changes I needed to make it work.

If you want a quick setup guide from someone that probably knows what he’s doing. check this link.

Once all this wa done, it was time to make the first migration. More on this in the next post.



Posted in Uncategorized | Leave a comment

Learning ASP.NET Core: My requirements


I need an aplication where I quickly create, edit and delete pages. Similar to what Wordpres has, but with less features. I also want to be able to write blog posts like this one and categorize them. Tags would be nice, but is not high priority. In addition to this, I want a way to write and organize programming challanges and organize them into categories in multiple levels.

I can (and will) use wordpress for this right now, but as a developer I want something that’s organized the way I want it, and I also want to learn ASP.NET Core.

Below is a structured list of the features I want along with the priority.

Required features:

These features are required to even make this useful. I won’t go into detail about each feature in this post. I’ll do that when I start implementation of each feature.

  • Database support (I want to store everything in a database)
  • User authentication (for admin)
  • pages (create, edit delete, automatic routing)
  • Blog posts / articles (with pagination)
  • Categories (Multiple levels)
  • HTML or Markdown editor/import for content.

Extra features:

These features are things that I would love to have. They are not prioritized, but some of them would be great to have for things to work smoothly.

  • File upload (admin
  • Browse uploade files
  • Tags
  • Comments
  • Editable menus

Som technical details

I want to run the app on Ubuntu 16.04 with Nginx. For the database I’ll be using PostgreSQL because I know it quite well,  and think it’s better than MySQL/MariaDB.

This isn’t really well through-out yet. It’s basically just a wish list, and will change in the future. I’ll update this post or make a new one when that happens.




Posted in ASP.NET Core, Projects | Leave a comment

Learning ASP.NET Core: Some quick testing

I’ve already done some tests with ASP.NET Core to see if it’s a viable option. So far, I’m quite impressed. I’m not sure if it’s because of the fact that I have a great IDE to work with, compared to when I’ve been doing PHP projects, or if  I just like the structure, and workflow better. I felt I could get up and running quicker with this, compared to something like Laravel. Getting started with Laravel felt much more overwhelming for some reason.

Anyway, Here’s what I’ve done so far.

  • Test ASP.NET Core on Linux, using this guide by Scot Hanselman, as well as the guide in the docs.
  • PostgreSQL database connection and migration with EF Core. Used several resources for this, will try to find them when I do the setup for my new project, if  decide to use PostgresQL.
  • A basic MVC app with a database and some editable content.

All of this was quite easy, considering I’ve never used this framework before.


Posted in ASP.NET Core | Leave a comment

Learning ASP.NET Core

For a very long time I’ve been using PHP for almost all of my server side scripting. A few years ago I decided to get into c# for some desktop stuff, but never did any web developent with it. I made a few small projects in classic ASP as well as the first version (I think) of ASP.NET back when I first started out with web develoment, but nothing else. Since linux hosting has been cheaper, I’ve been sticking to languages that works on Linux until recently. When ASP.NET Core first came out I was happy to hear about it, but from what I read, I felt it was a bit early to get into it.

Recently however, I decided to give it a try. I haven’t done any real development in it yet, but I decided to blog about my experience with it during development. I’ll do  the development on Windows, but my goal is to deploy on Linux.

What I want is a web app with a very basic system (doesn’t have to be user friendly) for editing pages, publish posts similar to this one. If this works out, I’ll try to port this site to ASP.NET Core but that will probably take a long time, and maybe won’t happen at all.

I don’t have that much time to work on this, and I also have some other projects (like small games) I want to work on.

Hopefully I, and maybe someone else can learn from the problems I run into.

I’ll do a more detailed specification of the project in my next post.

DISCLAIMER: I’m a PHP developer with very little experiance of .NET on the web. I won’t use best practices, I’ll try to talk about the problems I run into, as well as my experiance with ASP.NET Core. I haven’t worked much with the larger, more full fledged PHP frameworks either, but my experiance iwth them are pretty bad so far.

I’ve done some testing with ASP.NET Core, and so far, I’m quite impressed. I’ll do another post about that.




Posted in ASP.NET Core | Leave a comment

Welcome to programming exercises


I decided to start this site to collect some resources for aspiring programmers. I won’t focus on writing tutorials myself (even though it may happen in the futore), but rather try to point people in the right direction.

I’ll also try to write about some of my own small experimental projects.


Posted in Uncategorized | Comments Off on Welcome to programming exercises