Converting a Controller Method in MVC5 to async

I’m currently working on a Pluralsight course on ASP.NET and I have to admit I’m slow to adopt async methods in my code because it feels a little complex when non-async code is what I’m use to.  I’m feeling like since I’m doing this Pluralsight course I should really show best practices and clearly async controller methods is no doubt a best practice. I’m surprised it was actually so easy.  First, let me show you the code that I had written that is not async that I’m sure you are all familiar with. [crayon-57ecffce72c2e092838379/] All I had to change (besides adding the async name space for Task) was to have speakers return a task with the ToListAsync method and change the signature of the method to return a task. Here is the updated … Continue Reading

Using map instead of a for loop in ECMAScript 5 JavaScript

image.png

  Before [crayon-57ecffce747f7109809481/] After [crayon-57ecffce74807097405799/] Just Sayin... … Continue Reading

Seeding a Many to Many With Entity Framework and C# Dynamic

In the previous post, we created a single table (speakers) with Entity Framework Code First from a JSON file with Visual Studio 2015.  Now we will add a sessions table that has a many to many relationship to the speakers table.  That is, speakers can have multiple sessions and sessions can have multiple speakers.  We do that but simply creating another entity (sessions) and add to it a List of speakers and then adding to the existing speakers table a list of sessions.  The new table (models) look as follows. GitHub Repo: https://github.com/pkellner/EntityFrameworkSeedFromJSON [crayon-57ecffce75aed503030970/] Then,  we need to add sessions data (from the JSON file) but when we add the sessions, we need to add … Continue Reading

Seed Entity Framework Code First With JSON Using C# Dynamic

image.png

If you just want the short version, go to the this GitHub Repository and you’ll find a very simple project that I’ll explain in more detail here. https://github.com/pkellner/EntityFrameworkSeedFromJSON Below are the steps necessary to achieve converting JSON into Entity Framework Seeded data. Copy the JSON file into your Visual Studio project and make the build action (file property in VS) Embedded Resource. Next, find out the name of the embedded resource. If you just don’t know it or don’t want to spend time disassembling the project you can use the GetManifestResourceNames() method as shown below.  I find that is quicker and I don’t typically have those tools loaded when I need or want then. Once we have the manifest name, … Continue Reading

Follow

Get every new post delivered to your Inbox

Join other followers: