random techno tidbits
Evgeny
No progress here so far...
Posts by Evgeny
HDD vs SSD. Visual Studio benchmark.
May 4th
I’ve been using two WD Raptor 10k RPM HDDs in stripe for 3 years or so.
Recently, I finally ordered my first SSD (RealSSD C300 by Crucial). And I was really shocked by the overall performance gain it provided to the system. Not the advertized boot time, but rather typical developer daily workflows, like Visual Studio tasks, MS SQL backup/restore/select/update/etc. and so on. Technically, the most important thing about SSDs in comparison to HDDs is that their performance doesn’t degrade in about two orders when it comes to random reads. So running several hard IO consuming tasks at once isn’t a problem at all.
I’ve made some tests before and after the switch and one video comparing Visual Studio load time with pretty heavy solution in it + ReSharper enabled:
As you see, VS load gets about 300% improvement. This is nice.
The CrystalDiskMark tests (notice the tremendous random IO difference):
More >
Organizing view models in ASP.NET MVC (Part 3 of 3)
Mar 12th
This is the second part of Organizing view models in ASP.NET MVC (see Part 1, Part 2).
In this part I’ll give a sample of designing view models for handling forms in MVC. Suppose that we need to create a controller and stuff around it to handle form like the following.
For the sake of demo simplicity I keep the form simple:

More >
Organizing view models in ASP.NET MVC (Part 2 of 3)
Feb 1st
This is the second part of Organizing view models in ASP.NET MVC (see Part 1).
So, designing classes for your view models inevitably brings up some new concerns, like how should the Layout view models be implemented (master pages in terms of WebForms view engine).
From my experience, you should create an abstract class like SharedLayoutViewModel with all of the data properties required by your _Lauout.cshtml. Then, make all of the view models of views that use this layout inherit this class. You can use MVC Result filters to fill this model with data in a single place of your app, or, like I do, override the OnResultExecuting method in the common base class for your controllers, and fill it there.
To make your view models easy to find, organize them in a similar fashion as you do for views. I prefer putting all the view models in a single namespace (though in different project directories) and having full name as its class name like ProductsCreateViewModel (if you’re using ReSharper, set NamespaceProvider = False). This way I avoid need of explicit namespace reference in views and controllers. So my final layout looks like this:

In the next part I’ll give a sample of a simple form implemented using the described approach.
ASP.NET MVC bug binding collection of DropDownList?
Jan 26th
Recently, while experimenting with strongly-typed form helpers of MVC, I found a bug.
I posted a question at SO, but with no luck so far.
Generally, looks like DropDownFor is broken when trying to bind collection of form drop downs.
I have a workaround in form of using non-typed helper, but anyway hope to get things sorted out with strongly-typed one.
Organizing view models in ASP.NET MVC (Part 1 of 3)
Jan 12th
The internet is filled up with video tutorials like “Creating wiki using ASP.NET MVC in 15 minutes”. The problem of these tutorials is that they do not cover real life scenarios. They tend to use ViewData and ViewBag to transfer data into View. They use non-typed Html.TextBox() helper methods for generating forms. They use controller method parameters to transfer form data back to the controller one by one. Or, more worse, they directly put ORM entity into controller method parameters, which can lead to huge problems when practiced by a non-experienced developer.
So, such “rapid” approaches can be attractive for the person, whose job is to create such video tutorials (probably trying to compete with the famous RoR one).
But in a real life applications, you’ll probably want to use strongly-typed models, strongly-typed model-aware Html.TextBoxFor(m => ..) helpers for generating forms, and get strongly-typed POST data into controller method. In other words, you need acceptable maintainability for your projects in MVC.
So here are the rules to remember, if you’re going to develop with real MVC.
- Views to ViewModels is a one-to-one relationship. Define separate ViewModel class for every single View.
- View dictates ViewModel structure, not the controller.
- ViewModles are dummy DTOs, with no logic in them.
- Forget about calling
Request.IsAuthenticatedand similar in your views. ViewModel should contain ALL the data required to render the view.
In my next post I’ll describe how you can use strongly-typed models in generic view layouts (master pages in MVC2). See Part 2.
Razor: Html.RenderPartial vs Html.Partial, Html.RenderAction vs Html.Action – what one should use?
Dec 29th
This question can be confusing for people starting using ASP.NET MVC3.
Today, we have two ways to render partial and action stuff:
@Html.Partial("Details") @Html.Action("Index", "Home")
and
@{ Html.RenderPartial("Details"); } @{ Html.RenderAction("Index", "Home"); }
So what would you go with?
More >
MVC Recipe: Using strongly-typed html helpers in @helper
Jul 20th
Razor is a brand new view engine for MVC. I’ll describe a method to use strongly-typed helpers like TextBoxFor(m=>m.FirstName) in its reusable @helper blocks
If you never heard about it, then read on ScottGu blog.
Suppose you have a checkout model that has two addresses – billing and shipping:
public class CheckoutInfoForm { public CheckoutAddressForm BillingAddress { get; set; } public CheckoutAddressForm ShippingAddress { get; set; } }
While each address has model like this:
public class CheckoutAddressForm { public string FirstName { get; set; } public string LastName { get; set; } public string Address1 { get; set; } // and so on }
How would you generate address fields for both and reuse the markup?
More >
T-SQL: Using OUTPUT clause to insert original value.
Dec 22nd
The OUTPUT clause is the obvious choice in cases when you need to output what you insert/update/delete something from the database.
You can use DELETED and INSERTED prefixes to refer inserted and deleted rows. But what if you want to insert rows in to a table and OUTPUT a field from the source table that you DO NOT insert into destination table (and thus the field is not available through the INSERTED prefix).
Assume the following scenario. You have a table variable where you want to put identifiers of the source and destination records (to use those later):
DECLARE @InsertedAnimals TABLE (AnimalID INT, @CatID INT);
And you want to execute a statement like the below to insert cats, where Cat is a table of CatID (identity), Name (varchar):
INSERT INTO Cat (Name) OUTPUT Animal.AnimalID, INSERTED.CatID INTO @InsertedAnimals SELECT Name FROM Animal WHERE TYPE = 'Cat';
So that @InsertedAnimals would contain all the inserted AnimalID to CatID references. Obviously, this would not work, because you have no access to the Animal table in the OUTPUT clause. Only INSERTED prefix is available there.
BUT, there is a solution. More >