Pages

Wednesday 28 August 2013

MVC WebGrid - Sorting is not working with Enum datatype columns...

In MVC Web Grid,
If we bind Web Grid from server side for efficient paging and sorting, we may face this problem.
If one or more columns has Enum as Datatype then, sorting will not work properly for that columns.
In Sorting url, sort=ASC always. So sorting works only in one direction.

To resolve this,

we have to define columnNames property in grid.Bind() method.
For e.g.,

 var grid = new WebGrid();
 grid.Bind(data, new[] { "Id", "Name", "Note", "Date",  "EntityType" }, autoSortAndPage: false, rowCount: 10);




here,
EntityType is an Enum datatype.

Tuesday 27 August 2013

NHibernate Exception while updating records: could not delete collection [CHILD_TABLE_NAME]

While updating records using NHibernate, if we get the following exception :

could not delete collection: [CHILD_TABLE_NAME]

it is because of many to one relationship between two tables.
To resolve this exception,
we just need to add inverse="true" in mapping file of parent table. for e.g.,


 <bag name="ChildTables" generic="true" inverse = "true">
      <key>
        <column name="ParentTableId" not-null="true" />
      </key>
      <one-to-many class="ChildTable" />
  </bag>