I'm working on a project where we define some interfaces (possibly in a hierarchy) and the actual entities are generated runtime. Basically we don't know any entity at compile time and always work with the interfaces in queries etc.
Basically we have a structure similar to this:
Record / IRecord (represents our "root entity". All dynamic entities will implement this and it defines the HierarchyRoot)
IPerson
IEmployee : IPerson
In a generic grid method we use for grid binding we have this method:
var records = session.Query.All(RecordType).Cast<irecord>();
RecordType could be either IRecord, IPerson or IEmployee. Since our method returns a IQueryable<irecord>, we need to do the .Cast<irecord> for the signature to match. It works well when we do this with "real entities", but when RecordType = IPerson/IEmployee, the cast method results in this exception:
[KeyNotFoundException: The given key was not present in the dictionary.]
System.Collections.Generic.Dictionary2.get_Item(TKey key) +9627953
Xtensive.Orm.Linq.Translator.VisitCast(Expression source, Type targetType, Type sourceType) +591
Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) +239
Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) +294
Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) +3368
Xtensive.Linq.ExpressionVisitor
1.Visit(Expression e) +428
Xtensive.Orm.Linq.Translator.Visit(Expression e) +170
Xtensive.Orm.Linq.Translator.VisitSequence(Expression sequenceExpression, Expression expressionPart) +743
Xtensive.Orm.Linq.Translator.VisitWhere(Expression expression, LambdaExpression le) +64
Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) +5393
Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) +294
Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) +3368
Xtensive.Linq.ExpressionVisitor1.Visit(Expression e) +428
Xtensive.Orm.Linq.Translator.Visit(Expression e) +170
Xtensive.Orm.Linq.Translator.VisitSequence(Expression sequenceExpression, Expression expressionPart) +743
Xtensive.Orm.Linq.Translator.VisitAggregate(Expression source, MethodInfo method, LambdaExpression argument, Boolean isRoot, MethodCallExpression expressionPart) +367
Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) +4574
Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) +294
Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) +3368
Xtensive.Linq.ExpressionVisitor
1.Visit(Expression e) +428
Xtensive.Orm.Linq.Translator.Visit(Expression e) +170
Xtensive.Orm.Linq.Translator.Translate() +22
Xtensive.Orm.Linq.QueryProvider.Translate(Expression expression) +71
asked
May 18 '11 at 12:44
tmyklebust
48●5●5●9
Hello Terje,
Does IPerson inherits IRecord or at least IEntity? If not, then the translator doesn't know how to handle the cast.
If yes, could you publish or send me privately a part of your model with IRecord, IPerson and IEmployee interfaces?
Thanks in advance
Yes, all interfaces inherit IRecord which again inhert IEntity. I'll send you an e-mail with the model.
OK, waiting for the model.
OK, received the model. Will check both issues.