Redis as a cache server

Although Redis is much more than a cache, But it's possible to use as cache server specially in distributed applications. Redis lets you operate on the values and it's just a key value pair in memory database.

To getting start, get the latest version of Redis from here and install in your  windows machine (Server) by instruction and run it in your services. Redis runs in your server machine (you can have redis server and client in one machine which could be you client development machine) and you call it from client by a library... Continue

Simple command handler in .net

I want to introduce a simple command handler pattern in order to separate commands and queries of your applications, if it’s needed. Sometimes specially in large scale applications you need to have two layers for read and write separated and assign two teams to work on them.

You can use the pattern in this post based on complexity and needs of your application. I recommend that don’t call this CQRS pattern as it’s something completely different and more complex.


Get started and Create an interface with no any member:... Continue

Introducing sqlbulktools

In my previews blog post I wrote about Z.bulkOperation. I migrated to sqlbulktools just because it's free with the same ability!(to be frank). Now to see the reason of my migration, fire up visual studio and Install the latest version of the library using the following command in console package manager:

Install-Package sqlbulktools

And get started!

  1.  static void Main(string[] args)
  2.         {
  4.           &nb... Continue

Introducing Z.bulkOperation

Today I was tackling with a problem. It was about inserting and updating 200000 records of data. I just wanted to find a solution rather than writing Store Procedure. I just searched on the web and found a library named Z.BulkOperation

I dare say I had never seen handling this amount of data nicely in application level without even using a line of SQL code, it's awesome!

Fire up visual studio and a simple console or MVC application and install the package via:

PM> Install-Package Z.BulkOperations

PM> Install-Pac... Continue

Access to configuration in core

While I was working with core, I encountered with getting the configuration setting from json file and After searching on the web I found out that there would be different ways to do that. I tested the following one and it worked. There is different configuration in each version of core in Main method of program class. you should put the following configuration in this sample in main method because I didn’t tested it with other configurations to ensure you.

  1.  public static void Main(string[] args)
  2.      &nbs... Continue

Handling custom error in mvc

In mvc there is an custom error in web.config like below:

  1. <customErrors mode="On">
  2.  <error statusCode="404" redirect="~/404.html"/>
  3.  </customErrors>

Sometimes you want to redirect the user to your own custom error controller and log the error message. You can handle it! Firstly create your own Error controller:

  1.  public class ErrorController : Controller
  2.     {
  3.         public A... Continue

Call Web API from C#

If you search in the web for calling web API from C# Code not from URL, you will find lots of sample on get and hardly enough on POST! I don't know why but I want to share with you a simple example. As a usual open visual studio and create a web API project from MVC project template.

Suppose these two simple post and get API actions:

  1.         [HttpPost]
  2.         [Route("api/Test/PostValue")]
  3.         public IHttpActionResult Po... Continue

IP filtering attribute for web API

Recently I came up with a solution for filtering the API requests by filtering the server IP. This is used when you want to make the received requests private and secure. It's a simple helper and I hope it could be useful for you as well.

  1. public class AuthorizeApiIPAddressAttribute : ActionFilterAttribute
  2.     {
  3.         public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
  4.         {
  5.     &nbs... Continue

Multiple submit buttons in MVC

In MVC you can submit a form by @using(Html.BeginForm()). You can Post the model you have binded via this operation and command the begin form to post to a Post action:   @using(Html.BeginForm("Create","FooController")).

Now if you have more than one submit button to send the page content to different post action, there are few ways: one of them is to post the content to a specific action and then decide in it to redirect which action:


  1. <input type="submit" value="Field1" name=&quo... Continue

Why you can't project mapped entity in entity framework

If you have worked with entity framework for a long time with and linq of course, you probably have seen the Error: The entity cannot be constructed in a LINQ to Entities query. So when it happens and why? Think about the following peace of code:

  1. public IQueryable<Lesson> GetAllLessons(int termId)
  2. {
  3.     return from p in db.Lessons
  4.            where p.termId == termId
  5.            select ... Continue