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.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.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.ExpressionVisitor1.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's gravatar image

tmyklebust
48559

edited May 18 '11 at 12:45

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

(May 19 '11 at 05:22) Dmitri Maximov Dmitri%20Maximov's gravatar image

Yes, all interfaces inherit IRecord which again inhert IEntity. I'll send you an e-mail with the model.

(May 19 '11 at 06:03) tmyklebust tmyklebust's gravatar image

OK, waiting for the model.

(May 19 '11 at 06:05) Dmitri Maximov Dmitri%20Maximov's gravatar image

OK, received the model. Will check both issues.

(May 19 '11 at 06:26) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Fixed in revision 7536

answered May 20 '11 at 11:41

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA