Doesn't work in that using an entityview will not accomplish what I want to accomplish (see attached snippets). I've developed a "caching" data access adapter and I'm supporting sort expressions on entitycollections at the adapter level. For instance, if an entity is in the cache list, the first time any entity of that type is requested I fetch the entire collection and store it away ignoring the sort, and the predicate, etc. After the fetch (and on subsequent fetches) i apply the requested sort/predicate/top expressions to the cached collection. I don't support prefetch paths for cached entities (mostly code tables anyway). If a single entity is requested i copy the data from the cached entity and set isnew, isdirty, etc to false.
This is meant to support very simple caching with a manual expire for code table type entities. Honestly I just wanted to see if I could get it to work. The business layer is totally oblivious to the cache so that if i remove an entity type from the cache list I don't have to change anything and the data will be fetched from the database every time.
Below are some snippets, if you are interested in seeing the whole cache enabled data access adapter i can probably post it
private void ApplySortExpression(IEntityCollection2 collectionToFill,
ISortExpression sortClauses)
{
if (sortClauses != null && sortClauses.Count > 0)
{
List<EntityBase2> list = new List<EntityBase2>();
foreach (EntityBase2 temp in collectionToFill)
{
list.Add(temp);
}
list.Sort(new CustomCompare(sortClauses));
collectionToFill.Clear();
foreach (EntityBase2 temp in list)
{
collectionToFill.Add(temp);
}
}
}
from the custom compare class
public int Compare(EntityBase2 x, EntityBase2 y)
{
ISortClause clause;
this.clauseEnum = clauses.GetEnumerator();
int result = 0;
while (clauseEnum.MoveNext())
{
clause = clauseEnum.Current as ISortClause;
object field1 = x.Fields[clause.FieldToSortCore.Name].CurrentValue;
object field2 = y.Fields[clause.FieldToSortCore.Name].CurrentValue;
if (clause.FieldToSortCore.DataType.Equals(typeof(string)))
{
result = field1.ToString().CompareTo(field2.ToString());
}
else if (clause.FieldToSortCore.DataType.Equals(typeof(int)))
{
result = Convert.ToInt32(field1).CompareTo(Convert.ToInt32(field2));
}
else if (clause.FieldToSortCore.DataType.Equals(typeof(DateTime)))
{
result = Convert.ToDateTime(field1).CompareTo(field2);
}
else if (clause.FieldToSortCore.DataType.Equals(typeof(double)))
{
result = Convert.ToDouble(field1).CompareTo(Convert.ToDouble(field2));
}
else
{
throw new NotImplementedException();
}
if (result != 0)
{
if (clause.SortOperatorToUse == SortOperator.Descending)
{
result = -result;
}
break;
}
}
return result;
}