c# - Linq to SQL type mismatch -


i have type mismatch error when reading contents of table 'imagehighlight'.

in designer.cs table is:

public system.data.linq.table<imagehighlight>imagehighlights {         {         return this.gettable<imagehighlight>();     } } 

in code trying cache small table in method loadstaticcache() @ applicationstart can access contents later via gethighlightimages().

public class staticcache {      private static imagehighlight _images = null;      public static void loadstaticcache()     {         // images - cache using static member variable         using (var datacontext = new mhrdatacontext())         {             _images = datacontext.imagehighlights;         }     }      public static imagehighlight gethighlightimages()     {         return _images;     } } 

at code line _images = datacontext.imagehighlights; error

cannot implicitly convert type system.data.linq.table<holidayrentals.core.domain.linqtosql.imagehighlight> holidayrentals.core.domain.linqtosql.imagehighlight

they both same type.

datacontext.imagehighlights table iqueryable of imagehighlight. _imagess type imagehighlight. can not convert these types each other.

since want caching mechanism , _images indicates should contain multiple instance of images should change type of _images.

change code this:

public class staticcache {      private static list<imagehighlight> _images = null;      public static void loadstaticcache()     {         // images - cache using static member variable         using (var datacontext = new mhrdatacontext())         {             _images = datacontext.imagehighlights.tolist();         }     }     public static list<imagehighlight> gethighlightimages()     {         return _images;     } } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -