Hi all
In short:
I need to get an hash key from a predicate, so I call ".GetHashCode()"
But each different predicate but with the same filter return different hashkey. Do you have an idea on how to have a unique hashkey from the predicate content ?
For example if I build 2 predicate object with a filter like "WHERE myId=1", how to have a method that return the same hashkey for both predicate object ?
Now a bit more explanation on why I need it.
I've a process that fetch a lot of data from the database (sql server), make its job and then save the results.
Now, I need some unit test and a garantee that changes done to this process will not break customer cases, but we get maybe 20 or 30 databases on customer location, sometime with customer specific configuration.
Right now we've an nunit db set and we need to input a lot of data to recreate a real customer case in order to test it each night. So it take a lot of time and (of course) nobody do it, so we have maybe 100 nunit where we should have about 1000 to cover all the cases.
I think anybody know this sort of problem
So now ... I'm creating a tool that will generate in a file
- all data (from the customer db) needed for the process
- the results of the process
And then run the process from the data in the file, and then comparing the results
The process before:
Process -----> llblgen -----> db
The process after
Process -----> dataprovider ------> llblgen ------> db
I've 2 dataprovider right now:
- the normal one, that works as before and it only fetch data from llblgen
- the file dataprovider, that provide functionality to (un)serialize from/to file
the file dataprovider works in both way:
- serialization : fetch from the db, then serialize the result in the file
- deserialization: unserialize from the file and return this data (db is not needed anymore)
Ok now the heart of the problem:
In serialize mode, the dataprovider compute an hash key from the method name and from all parameters to get an unique key, then it serialize the data with this unique key.
In unserialize mode, it compute the same key and use it to retrieve data from the file and return it
Code example:
public CodeGetCode(int codId)
{
Code code = null;
string key = this.getUniqueHash(methodName(), codId);
switch (this.SerializeDirection)
{
case ComputeSerialization.Serialize:
{
code = this.dbCddProvider.Cache.GetCode(codId);
//serialize
this.ComputeFileManager.Serialize( code, key );
break;
}
case ComputeSerialization.Deserialize:
{
code = new Code();
this.ComputeFileManager.UnSerialize( code, key );
break;
}
}
if (code != null && code.Fields.State == EntityState.OutOfSync)
code = null;
return code;
The getHashKey method:
private string getUniqueHash(params object[] objList)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.Diagnostics.Debug.Write("getUniqueHash: ");
string hashCode;
foreach (object o in objList)
{
hashCode = o.GetType().FullName.GetHashCode().ToString() + o.GetHashCode().ToString();
System.Diagnostics.Debug.Write(string.Format("{0} ({1}) ||| ", o.ToString(), hashCode));
sb.Append(hashCode);
}
System.Diagnostics.Debug.WriteLine(" ----------> " + sb.ToString());
return sb.ToString();
}
My problem is that for predicate this key change for each object instance, even if the sql output from the predicate is the same.
Any idea?
Thank you for your help.