Nancy Street netTiers Bug and Hashing
Click to see the Site Map
HomeInfoMusicGalleryPetsGeoHobbiesGeo
Site MapWhat's NewRecent ChangesContactsServer StatisticsSite Information Home « Computers « DevBlog

Back to: Development Blog Contents

netTiers 2.0.0_cs26 DeepLoad bug

The DeepLoad method always uses the default database provider, not the one you specify. A way around the bug is to always wrap the DeepLoad in a transaction, like the following sample:

TransactionManager tm = DataRepository.Providers["starfleet"].CreateTransaction();
tm.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
DataRepository.Providers["starfleet"].FoobarProvider.DeepLoad(tm, fooentity,
   true,
   DeepLoadType.IncludeChildren,
   typeof(Template), typeof(ValidUnits));
tm.Commit();

A permanent fix is to correct one erroneous line number 850 in EntityProviderBaseCore.generated.cst as follows:

Before

entity.<%=compositePropertyName%> = DataRepository.<%= GetProviderName(pkClassName) %>.GetBy<%= pkProperty %>(transactionManager, <%= callParams %>);

After

entity.<%=compositePropertyName%> = DataRepository.<%= GetProviderName(pkClassName) %>.GetBy<%= pkProperty %>(<%= callParams %>);

Missing Hashing

The netTiers generated entity classes and the TList generic collection class do not override GetHashCode and therefore do not produce meaningful hash code values based upon their values or contents. The classes do have a "dirty" flag, but the flag is one-way and remains true after any change is made. A properly calculated hash code is better for "smart dirty" checking. Add the methods below to two template files.

EntityInstanceBase.generated.cst

///<summary>
/// PATCH TO create a real hash code
///</summary>
public override int GetHashCode()
{
int hash = 0;
<%for (int x=0; x < cols.Count; x++)
{
if ( cols[x].AllowDBNull )
{%>
hash ^= (this.<%=GetPropertyName(cols[x].Name)%> == null) ? 0 : this.<%=GetPropertyName(cols[x].Name)%>.GetHashCode();
<%} else { %>
hash ^= this.<%= GetPropertyName(cols[x].Name) %>.GetHashCode();
<% }
}%>
return hash;
}

ListBase.cst

/// <summary>
/// PATCH Returns a hash code made from all items in the collection.
/// </summary>
public override int GetHashCode()
{
int hash = 0;
foreach (T item in this)
{
hash ^= item.GetHashCode();
}
return hash;
}

Back to: Development Blog Contents


Contact Information | PGP Keys | Site Map | What's New | Visitor Book
Last Updated: 17-Sep-2007 8:42
Copyright © 1999-2007 Orthogonal Programming