Quantcast
Channel: Code – no dogma blog
Browsing all 132 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Adding class libraries to an ASP.NET 5 web application

When adding a class library to an ASP.NET 5 application you might get an error like “The following projects are not supported as references: – The project ClassLibrary1 has a target framework that is...

View Article


ASP.NET 5 Web Api Controller with multiple get methods

I have two other posts on multiple GET methods, both for Web Api 2, the first shows how to use routes like ‘http://…/api/values/geta’ and the second shows ‘http://…/api/values/22’ or...

View Article


The type ‘xxxx’ is defined in an assembly that is not referenced....

If you recognize the error from the title of this post, you can jump to the solution. The problem I have a ASP.NET 5 solution with two projects, a web application project and a class library project....

View Article

Image may be NSFW.
Clik here to view.

How to fix ‘No database providers are configured’ when scaffolding a...

If got this error when trying to scaffold a new controller (MVC and Web Api) for an ASP.NET 5 web app using Visual Studio 2015. There was an error running the selected code generator: 'No database...

View Article

Parameterized SQL WHERE IN clause c#

If you are using some legacy SQL in C# you’ll occasionally need to write a WHERE IN. Yon don’t want to end up writing something like the below, either directly or through some sort of loop. string...

View Article


Filtering a Dictionary by value with a List as the value

Filtering out entries in a dictionary is not too difficult when the key and value are simple. For example if you had – IDictionary oneToFourDictionary = new Dictionary {{ "one", 1 }, { "two", 2 }, {...

View Article

Image may be NSFW.
Clik here to view.

Why you should use IDictionary, IList, etc

Summary When returning objects from a method try to use IList, IDictionary, etc instead of List and Dictionary. This is especially important when the method is inside a class library which you...

View Article

Customizing a specific string inside a class using AutoFixture

Full source code. I’ve been using AutoFixture for a while with my unit tests. It creates objects with prefilled data, saving me the hassle of manually constructing them. Basic usage If you want a...

View Article


Entity Framework, checking the connection string of your context

Sometimes when using Entity Framework I want to verify that I’m connected to the database I think I’m connected to. Here’s how to check in Entity Framework 5, Entity Framework 6 and Entity Framework...

View Article


Web API 2 and ninject, how to make them work together

Full source code to download. I’ve been using ninject for a few years, but every time I use it with Web Api I hit some problem and they usually stem from not including the right nuget packages, not...

View Article

Image may be NSFW.
Clik here to view.

Getting Web API Exception Details from a HttpResponseMessage

The Problem It’s hard to get the details of an exception from a Web Api response when calling Web Api from a C# program. (Skip to the solution if you don’t care about the background), it even handles...

View Article

Entity Framework Core and calling a stored procedure

Download full source code here. I thought this would be easy, there is a method called ExecuteSqlCommand which takes the stored proc name and an array of parameters. I wanted to pass in two parameters...

View Article

Value cannot be null. Parameter name: constructor

Using Entity Framework I occasionally get the following error when reading from the database – exceptionMessage=Value cannot be null. Parameter name: constructor My Person class looked like this –...

View Article


Web API 2 Controller with multiple get methods

I have two other posts on multiple GET methods, one for ASP.NET 5 Web Api, and another for Web Api 2. It seems that every version of Web API changes how it handles default routes or route prefixes or...

View Article

Fluent Validation with Web Api 2

Full source code here. I wrote blog post in 2015 on using the Fluent Validation NuGet package for complex validation needs. In the post the validator checked that a create person request had at least...

View Article


Downloading an in-memory file using Web Api 2

Download full source code At first you think it’s going to be easy to download a file from Web Api, but as I discovered, it was not. In my case I wanted to load data from the database, perform some...

View Article

Web API 2 Controller with multiple GET methods – part 2

I have two other posts on multiple GET methods, one for ASP.NET 5 Web Api, and another for Web Api 2. Download full source code. A few months ago I wrote a post explaining how to create a controller...

View Article


Image may be NSFW.
Clik here to view.

Web Api 2 Without MVC

Download full source code. When building a Web Api 2 application there is much unneeded MVC baggage that comes along with it. To start with all the css, html and javascript can go, then most of the...

View Article

A simple Polly example with WebApi 2

Download full source code. If you are calling APIs and you haven’t heard about The Polly Project, you should check it out. It helps take care of many common problems like unreliable connections,...

View Article

Reusing Polly Policies with Dependency Injection

Download full source code. In my previous post “A simple Polly example with WebApi 2” I showed how to make a request to an unreliable endpoint protected by a Polly retry policy. For more on Polly see...

View Article
Browsing all 132 articles
Browse latest View live