Aspy – ASP.NET Session and Cache viewer

Posted by – May 10, 2012

Today I’ve released new version of Aspy. For those of you who don’t know what it is I recommend to visit project’s website at:

http://bytecarrot.com/aspy/.

I short words it is the ASP.NET Session and Cache viewer in a form of ASP.NET HTTP handler.

Current, 1.1.0 version is not a big changes but contains a feature requested by people who have started to use Aspy in theirs projects. The biggest problem with previous release was in viewing large values. There is no possibility to display for instance big XML in a table cell so the value was always truncated. Right now hovering at value cell shows small magnifying glass which clicked shows popup window with whole value. In addition from now ByteCarrot.Aspy.dll is signed and has strong name so it can be used with other signed assemblies.

More information, download and installation instructions can be found on Aspy website mentioned above. Below I’ve added screenshots presenting new feature added in this new version.

Saving place with jQuery and CSS based hover / context menu

Posted by – April 4, 2012

Monitors and theirs resolutions are getting bigger and bigger, but there is always a problem where to put all buttons, links and other controls to avoid overwhelmed UI. I am big fan of clean UI without unnecessary things used only from time to time. By default on screen should contain only the core information without distracting buttons, switches and things like that. Unfortunately all these additional stuff is required to work with an application so has to be implemented. The trickiest part is to make is available but in a subtle way.

I had such problem working on the last version of WebConsole. My solution is quite trivial and required a little bit of jQuery and CSS. I’ve solved the problem using as I call it “action menus”. These are context menu but activated by hovering mouse not right click. You can check how such “action menu” works in a screencast available below.

All three “action menus” presented in screencast above have the same HTML structure and use the same jQuery script. The look & feel has been totally customized in CSS so it is very useful and simple to use thing.

General structure of “action menu” and base CSS definition show two snippets below.

<div id="account-menu" class="action-menu">
    <span>Welcome <strong>Administrator</strong>!</span>
    <ul class="children">
        <li class="nowrap-text"><a href="#">Change Password</a></li>
        <li><a href="#">Sign Out</a></li>
    </ul>
</div>
div.action-menu {
    position: relative;
    margin: 0px;
    padding: 0px;
}

div.action-menu * {
    margin: 0px;
    padding: 0px;
}

div.action-menu a {
    text-decoration: none;
}

div.action-menu ul {
    list-style: none;
    display: none;
    position: absolute;
    z-index: 9999;
}

jQuery executed to make “action menu” reacting to hover is also very simple and straightforward.

// Adds action menu
function addActionMenus() {
    $('div.action-menu').hover(
        function () {
            $(this).addClass('hover');
            $(this).find('ul').show();
        },
        function () {
            $(this).removeClass('hover');
            $(this).find('ul').hide();
        }
    );
}

jQuery(function () {
    addActionMenus();
});

As I mentioned before rest of customization is done in CSS. The demo from screencast contains all code presented above and customizations made for each menu presented there. I am sharing it with you with hope it will be useful. You can download it here.

Please, let me know what do you think about this type of hiding actions available only in a particular contexts and my simple implementation.

jQuery UI tabs with vertical navigation

Posted by – March 18, 2012

I am currently working on a settings view for the WebConsole application. This view will consist of many smaller views for editing configuration. I am using jQuery UI is the obvious choice for me was Tabs control available in this library. Unfortunately I was not very happy with its default layout. The problem was that my main menu is laid out horizontally so I wanted to distinguish somehow tabs which are just below it. I have solved it changing navigation in tabs from horizontal to vertical. Fortunately it turned out very easy and required only some CSS. Below I am presenting the result, CSS and HTML/Razor source code.

jQuery UI tabs with vertical navigation

HTML/Razor source code

@model ByteCarrot.WebConsole.Web.Controllers.Settings.SettingsViewModel</pre>
<div id="settings">
<ul>
	<li><a href="@Url.Action(MVC.Account.List())">Users</a></li>
	<li><a href="@Url.Action(MVC.Account.List())">Settings 1</a></li>
	<li><a href="@Url.Action(MVC.Account.List())">Settings 2</a></li>
</ul>
</div>
<script type="text/javascript">
     $(function () {
         $("#settings").tabs();
     });
</script>

CSS source code

div#settings {
    position: relative;
    padding-left: 200px;
}

div#settings > div {
    min-height: 300px;
}

div#settings .ui-tabs-nav {
    position: absolute;
    left: 0px;
    top: 0px;
    bottom: 0px;
    width: 200px;
    padding: 5px 0px 5px 5px;
}

div#settings .ui-tabs-nav li {
    left: 0px;
    width: 195px;
    border-right: none;
    overflow: hidden;
    margin-bottom: 2px;
}

div#settings .ui-tabs-nav li a {
    float: right;
    width: 100%;
    text-align: right;
}

div#settings .ui-tabs-nav li.ui-tabs-selected {
    border: none;
    border-right: solid 1px #fff;
    background: none;
    background-color: #fff;
    width: 200px;
}

If you are fan of .less project here is the same CSS in LESS format:

div#settings
{
    position: relative;
    padding-left: 200px;

    > div
    {
        min-height: 300px;
    }

    .ui-tabs-nav
    {
        position: absolute;
        left: 0px;
        top: 0px;
        bottom: 0px;
        width: 200px;
        padding: 5px 0px 5px 5px;

        li
        {
            left:  0px;
            width: 195px;
            border-right: none;
            overflow: hidden;
            margin-bottom: 2px;

            a
            {
                float: right;
                width: 100%;
                text-align: right;
            }
        }

        li.ui-tabs-selected
        {
            border: none;
            border-right: solid 1px #fff;
            background: none;
            background-color: #fff;
            width: 200px;
        }
    }
}

I hope it will be useful.

Fluent NHibernate – mapping one to one relation

Posted by – March 7, 2012

Few weeks ago I’ve started new project based on ASP.NET MVC, jQuery and NHibernate. It has some part of functionality inspired by ELMAH but mainly goes in a different direction addressing some additional scenarios and it is called WebConsole. It is able to catch exceptions from ASP.NET application and save them with whole context in centralized database. It can also log every request and response even if there was no exception. As you can see everything is spinning around HTTP request and response model.

In order to store information about HTTP communication I had to create NHibernate entities and map them to a database. After some short brainstorming I came up with three basic entities:

Activity – representing single “act” of communication between a client and a server

public class Activity : Entity
{
    // ... some properties and methods removed for readability

    public virtual int Id { get; set; }

    private Request _request;
    public virtual Request Request
    {
        get { return _request; }
    }

    public virtual void Add(Request request)
    {
        if (_request != null)
        {
            _request.Activity = null;
        }
        _request = request;
        _request.Activity = this;
    }

    private Response _response;
    public virtual Response Response
    {
        get { return _response; }
    }

    public virtual void Add(Response response)
    {
        if (_response != null)
        {
            _response.Activity = null;
        }
        _response = response;
        _response.Activity = this;
    }
}

Request – representing request made by the client

public class Request : Entity
{
    // ... some properties  and methods removed for readability

    public virtual int Id { get; set; }

    public virtual Activity Activity { get; set; }
}

Response – representing response from the server

public class Response : Entity
{
    // ... some properties  and methods removed for readability

    public virtual int Id { get; set; }

    public virtual Activity Activity { get; set; }
}

During one Activity there can be no more than one Request and Response. With this assumptions in mind I’ve started thinking how to map these relations using Fluent NHibernate. It was obvious for me that this are one to one relations, but turned out it is not so obvious how to map them. After some googling, playing with the code and a cup coffee I found right configuration which work nice.

From the Activity side relations has been mapped in a standard way by using HasOne method with some other modifiers for the access and lazy loading. One thing worth mention is Id mapping with automatically generated values.

public sealed class ActivityMap : ClassMap
{
    public ActivityMap()
    {
        // ... some mappings removed for readability

        Id(x => x.Id);

        HasOne(x => x.Request).Access.CamelCaseField(Prefix.Underscore)
                .Cascade.All().LazyLoad();

        HasOne(x => x.Response).Access.CamelCaseField(Prefix.Underscore)
                .Cascade.All().LazyLoad();
    }
}

From the Request and the Response mapping side thing looks quite different. This is because I had to “tell” that Id should not be automatically generated but taken from the Activity. Additionally HasOne relation looks different because it has to act as a foreign key and be constrained to values of the Activitie’s identifier (Id).

public sealed class RequestMap : ClassMap
{
    public RequestMap()
    {
        // ... some mappings removed for readability

        Id(x => x.Id).GeneratedBy.Foreign("Activity");

        HasOne(x => x.Activity).Constrained().ForeignKey();
    }
}

public sealed class ResponseMap : ClassMap
{
    public ResponseMap()
    {
        // ... some mappings removed for readability

        Id(x => x.Id).GeneratedBy.Foreign("Activity");

        HasOne(x => x.Activity).Constrained().ForeignKey();
    }
}

At the end we came up with a solution where the main entity is responsible for generating identifiers and all other entities in one to one relation use them as theirs primary and foreign keys.

C# 4.0 Named Arguments – example usage

Posted by – August 24, 2010

One of the new features introduced in C# 4.0 were named arguments. There was a lot of discussion in the Internet about them and theirs pros and cons. Of course named arguments can be abused like any other part of C# but I think that when used wisely are able to make your code more readable and easier to understand without the knowledge what is hidden behind the scene. Few days ago I was working on integration tests for REST API exposed by a startup I am working on with my team. Each test required some “execution context” and a way to inform “infrastructure” that after execution whole environment should be cleaned up (e.g. database). Because I use NUnit as a runner the first idea that came to my mind was to utilize [SetUp] and [TearDown] methods. But after some prototyping I realized that the solution is hard to understand and obfuscates the tests. Next day after short chat with @lesnikowski new idea popped into my mind: I can create “execution context” with lambdas and named arguments! The example below shows how I have changed the idea into real code.

[Test]
public void Add_WhenInvokedShouldAddNewExternalAudioFolder()
{
    Execute(test: () =>
    {
        var json = WebApiClient.ExternalAudioFolder.Add("My folder", "My description");
        var message = json.DeserializeJson<AddMessage>();

        Assert.That(message.Result, Is.EqualTo(Message.Success));
    },
    inContextOf: Account.Basic,
    cleanUpAfter: true);
}

What do you think about the code above? Do you have any additional ideas how to improve readability of this “execution context”?

Fluent NHibernate conventions II – example for enumerations

Posted by – May 20, 2010

Most of the time I do not have to touch Fluent NHibernate conventions I have created some time ago. But from time to time I find in mappings some common scenario which is a good candidate to become a convention. This time I found that every time I am mapping a property of enumeration type I have to specify its length manually.

Because I hate redundant work I have defined a Fluent NHibernate convention presented below.

using System;
using System.Linq;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.AcceptanceCriteria;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.Instances;

namespace ExampleConventions
{
    public class EnumColumnLengthConvention
        : IPropertyConvention, IPropertyConventionAcceptance
    {
        public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
        {
            criteria.Expect(x => x.Property.PropertyType.IsEnum)
                .Expect(x => x.Length == 0);
        }

        public void Apply(IPropertyInstance instance)
        {
            var names = Enum.GetNames(instance.Property.PropertyType);
            instance.Length(names.Max(name => name.Length));
        }
    }
}

The convention is really simple. Its whole logic can be found in Apply method and I think it is self explanatory so there is nothing to describe here.

[BUG] invalid exec_format “ir”, no %s

Posted by – May 11, 2010

Today I’ve switched from the default, C based implementation of Ruby to new version of IronRuby (1.0). After installation I wanted to update gems, install rake tool and of course at this point problems started. Command for updating gems displayed below:

igem update --system

produced output like this:

Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.6
Updating RubyGems to 1.3.6
Installing RubyGems 1.3.6
ERROR:  While executing gem ... (Gem::Exception)
       [BUG] invalid exec_format "ir", no %s

After some research turned out that RubyGems assumes that Ruby executable contains “ruby” word in the name. In case of IronRuby the name is “ir.exe” so in my opinion this strange behavior can be treated as a bug in RubyGems. I hope it will be fixed in next release but before that will happen here are the steps to workaround the problem and update gems:

1. Create path: [IronRuby folder]\Lib\ruby\1.8\rubygems\defaults
2. Create file ironruby.rb and add it to the path from step 1
3. Open ironruby.rb and add code from the snippet below

module Gem
  def self.default_exec_format
    exec_format = ConfigMap[:ruby_install_name].sub('ruby', '%s') rescue '%s'
    #unless exec_format =~ /%s/ then
    #  raise Gem::Exception,
    #    "[BUG] invalid exec_format #{exec_format.inspect}, no %s"
    #end
    exec_format
  end
end

That is it. Now RubyGems will use new implementation of default_exec_format and everything should work as expected.

Hope this helps.

Ruby for Windows with debug support

Posted by – February 10, 2010

I mentioned somewhere in previous posts I am playing a little with Ruby and Ruby on Rails. Because I do not have an experience yet, there are a lot of situations where I need a debugger to figure out how something works. Unfortunately before I was able to debug anything I spend a lot of time trying to enable debugging in RubyMine. The main problem was in Ruby gems responsible for debugging. This gems are native C libraries and have to be compiled before usage. Of course you can guess that compilation did not work as expected. After long fight and few hours with Google I have managed to prepare a version of Ruby which can be used with RubyMine to debug applications.

Because Ruby for Windows does not require any installation I am able to easily provide you the version I have build mostly in order to save your time and do not describe whole procedure I had to follow during compilation.

The package contains Ruby 1.8.7 for Windows with following gems:

  • actionmailer (2.3.5)
  • actionpack (2.3.5)
  • activerecord (2.3.5)
  • activeresource (2.3.5)
  • activesupport (2.3.5)
  • albacore (0.1.1, 0.1.0)
  • columnize (0.3.1)
  • linecache (0.43)
  • net-sftp (2.0.4)
  • net-ssh (2.0.19)
  • rack (1.1.0, 1.0.1)
  • rails (2.3.5)
  • rake (0.8.7)
  • RedCloth (4.2.2)
  • ruby-debug (0.10.3)
  • ruby-debug-base (0.10.3)
  • ruby-debug-ide (0.4.9)
  • rubyzip (0.9.4, 0.9.1)
  • sqlite3-ruby (1.2.5)

Installation is very simple. Uncompress files to C:\Ruby directory and add C:\Ruby\bin path to PATH environment variable.

Download Ruby 1.8.7 for Windows with debug support

IronRuby/RHTML based templates for .NET

Posted by – December 8, 2009

.NET Logo

During last few days I was prototyping some of new features I would like to add to ByteCarrot application. One of them is new template engine which will replace current XSLT based solution. I wanted something with more friendly syntax, something easy to create, change and maintain. I took a look at many template engines available for .NET platform but none of them met my needs. I thought that it would be nice to have solution with scripting support and syntax similar to this available in default ASP.NET MVC view engine.

After digging I have found an ASP.NET MVC application prototype with view engine based on IronRuby. It was created by Phil Haack‘s team and its syntax was exactly the same as RHTML used in Ruby on Rails views. It turned out that this engine was exactly what I needed, so I have taken parts of the code and adapted it to my scenario. The result is amazing because now I have fully functional templates engine with support of dynamic language where I can handle every possible HTML generation scenario.

As an attachment to this post I have added the code created during prototyping. The code contains few classes where the most important is RhtmlEngine. It has very simple, self-expanatory interface and acts as an “entry point” for using mentioned templates engine. Below you can find two samples showing capabilities of my solution but if you want to take a look at the implementation and make your hands dirty feel free to download the code and play with it for yourself.

public class RhtmlEngine
{
    public Result Render(object model, string temlateFile, string targetFile)
        ...
    public Result Render(object model, StreamReader rhtml, StreamWriter writer)
        ...
}

Simple template

The templates engine requires three things to be able to generate HTML:

  • Model representing the data which should be presented in form of HTML page,
  • Template defining how model should be presented,
  • Target where generated HTML page should be saved.

Listing below shows simple template generating a header and a list of hobbies. Notice that IronRuby blocks are embedded exactly the same as Visual Basic .NET or C# code is embedded in ASP.NET MVC views.

SimpleTemplate.rhtml

<html>
    <body>
        <h1>Hi! My name is: <%= model.FirstName %><%= model.LastName %></h2>
        I like:
        <ul>
        <% model.Hobbies.each do |hobby| %>
			<li><%= hobby %></li>
        <% end %>
        </ul>
    </body>
</html>

Template shown above can be used to generate an HTML representation of the following model:

var model = new SampleModel
{
    FirstName = "Marcin",
    LastName = "Obel",
    Hobbies = new List<string>
    {
        "yachting",
        "fishing",
        "cycling"
    }
};

As you can notice looking at listing below, because the templates engine is very simple, you need only one line to change the model into HTML page.

var result = new RhtmlEngine().Render(model, "SimpleTemplate.rhtml", "SimpleHtml.html");

In result (as shown below) the code above will produce clean HTML filled in with the data from model.

SimpleHtml.html

<html>
    <body>
        <h1>Hi! My name is: MarcinObel</h2>
        I like:
        <ul>
            <li>yachting</li>
            <li>fishing</li>
            <li>cycling</li>
        </ul>
    </body>
</html>

More advanced example

The example above does not show the most powerful part of this solution which is in fact inherited from IronRuby itself. Because templates are based on fully functional, dynamic language there is a possibility to extend basic features like loops and if statements (available in all templates engines) with things like functions, classes or even use some functionalities available in .NET Framework. Next example extends this one mentioned in previous section. In the listing below you can notice two new functions:

  • encode - uses HttpUtility class from .NET Framework to encode HTML code
  • render_li – renders an item of HTML list

AdvancedTemplate.rhtml

<%
require 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
include System::Web

def encode(text)
    HttpUtility.HtmlEncode(text)
end

def render_li(text)
    writer.Write "<li>#{text}</li>";
end
%>

<html>
    <body>
        <h1>Hi! My name is: <%= model.FirstName %><%= model.LastName %></h2>
        I like:
        <ul>
        <% model.Hobbies.each do |hobby|
                 render_li hobby
             end %>
        </ul>
        <pre>
            <%= encode model.UglyJavaScript %>
        </pre>
    </body>
</html>

In order to present a usage of custom IronRuby function added to the template, below you can find extended model from previous example. Now the model contains additional property named UglyJavaScript containing JavaScript code which should be encoded before it can be presented in HTML.

var model = new SampleModel
{
    FirstName = "Marcin",
    LastName = "Obel",
    Hobbies = new List<string>
    {
        "yachting",
        "fishing",
        "cycling"
    },
    UglyJavaScript = @"<script type='text/javascript'>window.close();</script>"
};

var result = new RhtmlEngine().Render(model, "AdvancedTemplate.rhtml", "AdvancedHtml.html");

Like in previous example after passing the model and the template into engine we receive an HTML.  This time as you can see it contains JavaScript code from model encoded using .NET Framework functionality in order to be able to display it.

<html>
    <body>
        <h1>Hi! My name is: MarcinObel</h2>
        I like:
        <ul>
        <li>yachting</li><li>fishing</li><li>cycling</li>
        </ul>
        <pre>
        &lt;script type='text/javascript'&gt;window.close();&lt;/script&gt;
        </pre>
    </body>
</html>

Resources

Fluent NHibernate conventions – examples

Posted by – November 26, 2009

Fluent NHibernateFluent NHibernate is my favorite extension for NHibernate. I am using it since early betas and I have to say that I love it. One of its underestimated features are conventions. I decided to extract some of them from one of my projects and provide real life examples how they can be used. My conventions are listed below but if you need more information visit Fluent NHibernate Wiki where this feature is described in detail.

ColumnNullabilityConvention – says that if nullability for column has not been specified explicitly, should be set to “NOT NULL”.

public class ColumnNullabilityConvention
    : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Nullable, Is.Not.Set);
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.Not.Nullable();
    }
}

CreatedAtPropertyAccessConvention – says that every property named CreatedAt should be accessed through camel case field hidden behind it.

public class CreatedAtPropertyAccessConvention
    : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.Name == "CreatedAt");
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.Access.ReadOnlyPropertyThroughCamelCaseField(
            CamelCasePrefix.Underscore);
    }
}

ForeignKeyConstraintNameConvention – says that name of every foreign key constraint representing one to many relation should consist of names of entities for which it was specified.

public class ForeignKeyConstraintNameConvention
    : IHasManyConvention
{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        instance.Key.ForeignKey("{0}_{1}_FK".AsFormat(
        instance.Member.Name, instance.EntityType.Name));
    }
}

ForeignKeyNameConvention – says that name of every column containing foreign key id should consist of name of type which it points to with “Id” suffix.

public class ForeignKeyNameConvention : IHasManyConvention
{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        instance.Key.Column(instance.EntityType.Name + "Id");
    }
}

PrimaryKeyNameConvention - says that name of every column representing primary key should consist of entity name and “Id” suffix.

public class PrimaryKeyNameConvention : IIdConvention
{
    public void Apply(IIdentityInstance instance)
    {
        instance.Column(instance.EntityType.Name + "Id");
    }
}

ReferenceConvention – says that name of column referenced in many to one convention should consist of entity name and “Id” suffix.

public class ReferenceConvention : IReferenceConvention
{
    public void Apply(IManyToOneInstance instance)
    {
        instance.Column(instance.Property.PropertyType.Name + "Id");
    }
}

StringColumnLengthConvention – says that if length for string column has not been specified, it should be set to 100.

public class StringColumnLengthConvention
    : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Type == typeof(string))
            .Expect(x => x.Length == 0);
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.Length(100);
    }
}

TableNameConvention – says that if name for table has not been specified, it should be created using concatenation of entity name and “s” suffix.

public class TableNameConvention
    : IClassConvention, IClassConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IClassInspector> criteria)
    {
        criteria.Expect(x => x.TableName, Is.Not.Set);
    }

    public void Apply(IClassInstance instance)
    {
        instance.Table(instance.EntityType.Name + "s");
    }
}

At the end the most important thing which shows that such conventions make sense. With default Fluent NHibernate conventions DDL generated by NHibernate for MySQL looked like this:

alter table `Athlete`  drop foreign key FK9221C9B94070A6F0

drop table if exists Countries

drop table if exists `Athlete`

create table Countries (
     Id INTEGER NOT NULL AUTO_INCREMENT,
     Name VARCHAR(255),
     primary key (Id)
)

create table `Athlete` (
     Id INTEGER NOT NULL AUTO_INCREMENT,
     DisplayName VARCHAR(255),
     Email VARCHAR(255),
     Password VARCHAR(255),
     CreatedAt DATETIME,
     IsActive TINYINT(1),
     Country_id INTEGER,
     primary key (Id)
)

alter table `Athlete`
	add index (Country_id),
	add constraint FK9221C9B94070A6F0
	foreign key (Country_id)
	references Countries (Id)

When I have applied conventions mentioned above to my fluent mappings DDL looks like this:

alter table Athletes  drop foreign key Athletes_Country_FK

drop table if exists Athletes

drop table if exists Countries

create table Athletes (
     AthleteId INTEGER NOT NULL AUTO_INCREMENT,
     DisplayName VARCHAR(100) not null,
     Email VARCHAR(100) not null,
     Password VARCHAR(100) not null,
     CreatedAt DATETIME not null,
     IsActive TINYINT(1) not null,
     CountryId INTEGER,
     primary key (AthleteId)
)

create table Countries (
     CountryId INTEGER NOT NULL AUTO_INCREMENT,
     Name VARCHAR(100) not null,
     primary key (CountryId)
)

alter table Athletes
	add index (CountryId),
	add constraint Athletes_Country_FK
	foreign key (CountryId)
	references Countries (CountryId)

For me it looks much better. Additionally I have made it once and that is it. Now I have to care only about domain model and business logic without thinking about not so important stuff lake names of database objects.