Sorry I didnt provide more detail Cor....Heres an example of what im
doing...
//begin code to put collection in cache on SalesRegion class
public static IList getAllActiveSal esRegionsCached ()
{
if( System.Web.Http Context.Current .Cache["getAllActiveSa lesRegions"] ==
null)
resetCacheOfAll ActiveSalesRegi ons();
return
(ArrayList)Syst em.Web.HttpCont ext.Current.Cac he["getAllActiveSa lesRegions"];
}
public static void resetCacheOfAll ActiveSalesRegi ons()
{
System.Web.Http Context.Current .Cache["getAllActiveSa lesRegions"] =
SalesRegion.get AllActiveSalesR egionsQuery();
}
public static IList getAllActiveSal esRegionsUncach ed()
{
return getAllActiveSal esRegionsQuery( );
}
private static IList getAllActiveSal esRegionsQuery( )
{
string theQuery = "from SalesRegion s where s.active = true";
return Db.Session.Crea teQuery(theQuer y).List();
}
//end code cache logic....
//then this is where i use the cached collection in a code behind...
ArrayList salesRegions = SalesRegion.get AllActiveSalesR egionsCached();
ArrayList allSelectedRegi onsInActiveColl ection =
((InvoiceLineIt em)i.invoiceLin eItems[0]).getAllSalesRe gionsThatAreSel ectedInTheActiv eCollection();
for(int x=0; x<salesRegions. Count; x++)
{
if(allSelectedR egionsInActiveC ollection.Conta ins(
((SalesRegion)s alesRegions[x]) ) )
row.Add("X");
else
row.Add("");
cnt++;
}
if i use the uncached version the contains logic works fine but if i use the
cached version contains fails....
thanks again for all your help
"Arne Vajhøj" <ar**@vajhoej.d kwrote in message
news:jSp_g.2267 2$2g4.4823@duke read09...
netnet wrote:
>No? Could you go into more detail? Im actually using the
myCol.Contains (foo) method.
Contains uses Equals to see if objects are identical (and
some other ways, but Equals is probably the most relevant for you).
If you have not implemented Equals, then it uses Object Equals,
which just test if it is the same object (same location in memory) - not
if the values are the same.
To illustrate the point try and run the following code:
using System;
using System.Collecti ons.Generic;
namespace E
{
public class A
{
private string s;
public A() : this("")
{
}
public A(string s)
{
this.s = s;
}
public string S
{
get
{
return s;
}
set
{
this.s = value;
}
}
public override string ToString()
{
return s;
}
}
public class B
{
private string s;
public B() : this("")
{
}
public B(string s)
{
this.s = s;
}
public string S
{
get
{
return s;
}
set
{
s = value;
}
}
public override string ToString()
{
return s;
}
public override bool Equals(object o)
{
if (o is B)
{
if (s == ((B)o).S)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
public override int GetHashCode()
{
return s.GetHashCode() ;
}
}
public class MainClass
{
public static void Main(string[] args)
{
List<Alst1 = new List<A>();
lst1.Add(new A("test"));
Console.WriteLi ne(lst1.Contain s(new A("test")));
List<Blst2 = new List<B>();
lst2.Add(new B("test"));
Console.WriteLi ne(lst2.Contain s(new B("test")));
}
}
}
(it is using generics, but that nothing to do with the effect)
Arne