Filter by Object Type

ScaleOut Software NamedCache API
Returning Objects by Type

Suppose you have instances of these classes

Example classes
 2class Stock
 4    [SossIndex]
 5    public string Ticker { get; set; }
 6    [SossIndex]
 7    public DateTime DelistingDate { get; set; }
 9    public decimal TotalShares { get; set; }
10    public decimal Price { get; set; }
14class SmallCapStock : Stock
written to a NamedCache on StateServer. To retrieve all StockStock instances - including any SmallCapStock instances - and print the stock's Tickers to the console, you could use code like:
1NamedCache cache = CacheFactory.GetCache("Stocks");
2foreach (Stock s in cache.QueryObjects<Stock>()) {
3    Console.WriteLine(s.Ticker);

The QueryObjectsT method returns all objects in a given NamedCache of the same type as or any subtype of its generic type parameter.

The generic type parameter T in QueryObjects and QueryKeys must correspond to a type which either has properties annotated with the SossIndexAttribute or, the type itself is annotated with SossIndexAttribute. Otherwise, a runtime exception will be thrown indicating that the type requested has no type signature information in the property index.

Querying Keys of Objects by Type

If you wanted to update objects queried from the StateServer, retrieving the keys of the objects might be more convenient:

1foreach (CachedObjectId<Stock> key in cache.QueryKeys<Stock>()) {
2    Stock s = key.Value;
3    // .. perform some update on the stock
4    cache[key] = s;

Note that QueryKeysT returns instances of the stronly-typed class CachedObjectIdT rather than CachedObjectId. CachedObjectIdT's Value property may then be used to retrieve the object from the NamedCache and cast it to the expected type.


The return type of QueryObjectsT and QueryKeysT is an IQueryableT. In addition to allowing objects of a given type stored in a NamedCache to be enumerable, QueryObjectsT and QueryKeysT can serve as a a LINQ data source for arbitrary LINQ queries using the LINQ pattern. Combining QueryObjectsT and QueryKeysT with LINQ queries is covered in Using LINQ.

See Also


Other Resources