I’ve been interested in learning more about functional C#, and how it differs from the OOP style C# that I’ve been doing for years. Ed Charbeneau gave a talk on this topic at CodeMash back in January, the main lesson being how to score a poker game using C# and functional principals and the samples. In this blog entry I will be reviewing a few of the functional principals I took away from the presentation— there are many more but here’s a short list: Continue reading “Functional Programming with C#”
co-authored by Joseph Dotson
We are working on a project where the data access methodology for the application was defined and provided by the client. While this approach accomplishes the tasks of accessing data in SQL Server we found that we were duplicating code making small changes to new files but largely repeating code to access new tables in the database. We decided to look at dynamic code in C# to solve this problem and reduce redundancy in the code base.
I use Windows Live Writer( for no other reason than it is simple and works) to create blog posts. I am running Windows 8 and downloaded Live Writer 2012. I then began the seemingly simple steps to configure it to publish directly to SharePoint. First, I started Live Writer and followed the steps in the wizard and received an error stating: “Problem with blog server – server error 2041 occurred. Attempted to perform an unauthorized operation.” Here are the steps to reproduce the error.
I was working on an MVC 4.0 web application that contained some WebAPI controllers. The requirement was to secure the site using Windows Authentication. However, only the web pages required security but, the Api controllers did not. I changed the web.config and IIS 7.5 to provide Windows Authentication. I then added an authorize attribute to my MVC controllers like “[Authorize(Roles = “FooWebUsers”)]”. Since, the WebAPI controllers did not need security I added the [AllowAnonymous] attribute to those controllers.
I tested the site and discovered the MVC Controllers were properly secured, prompting a login – ok good. Hit one of the API routes in fiddler and got a NT challenge and response or prompt for Login. What’s going on here? I added [AllowAnonymous] to the API controllers – not working. After much digging around I found what I wanted by implementing a custom Authorization attribute. Here’s the steps I went through to implement this.
I find when reviewing code to solve a relatively mundane process with several procedural steps that no pattern is used. The code becomes difficult to support and the intent of the process is muddied by the lack of design. Usually due to two leading factors. The first factor is lack of experience in the developer – create one class and a few methods with no pattern and you got it – right? Wrong. This coding style throws your fellow developers to the wolves.
There has been a lot of buzz in the development community concerning no SQL databases. That’s right a database used to persist data for an application that involves no SQL period. How does this work? How do I construct tables or even perform basic CRUD operations with out SQL? The answer is you don’t. RavenDB is a schema free database with no concept of tables and rows or mappings or the typical stuff that goes with SQL server or MySQL and so on. It is a place you can simply dump your application objects into and easily access later. This alone saves a good deal of time.
Finding duplicate rows in a table can be done very simply by using Common Table Expressions knows as CTE’s along with the SQL Server built-in function ROW_Number() with the <PARTITION BY> and <ORDER BY> arguments found in SQL Server 2005 or later. In the sample below I’m looking for products that exist in the Products table more than once where the ProductName, Quantity, and Price are the same.