I have entity with "Virtual field", something like:

public class Another : Entity
    [Field, Key]
    public int Id { get; private set; }

    [Field(Length = 100)]
    public string Text { get; set; }

    public MyEntity MyEnt { get; set; }

    private static readonly Expression<Func<Another, string>> MyEntTextExpression = e => e.MyEnt == null ? null : e.MyEnt.Text;

    private static readonly Func<Another, string> MyEntTextExpressionCompiled = MyEntTextExpression.Compile();

    public string MyEntText { get { return MyEntTextExpressionCompiled(this); } }

    public static class CustomLinqCompilerContainer
        [Compiler(typeof(Another), "MyEntText", TargetKind.PropertyGet)]
        public static Expression MyEntText(Expression assignmentExpression)
            return MyEntTextExpression.BindParameters(assignmentExpression);

and query:

var query = Query.All<Another>().Where(a => a.MyEntText.Contains("e")).Select(a => new { a.Id, a.MyEntText });
                    foreach (var item in query)
                        // OK

                    var aggregateQuery = from q in query
                                         select new { Item = q, FakeKey = 0 }
                                             into i
                                             group i by i.FakeKey;
                    var aggregate = aggregateQuery.Select(a => new { Count = a.Count() });

                    foreach (var item in aggregate)
                        // OK

                    // Exception!
                    var nowCount = aggregate.FirstOrDefault();

                    var futureCount = Query.ExecuteFutureScalar(() => aggregate.FirstOrDefault());

System.ArgumentOutOfRangeException was unhandled Message=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Source=mscorlib ParamName=index

var nowCount = aggregate.FirstOrDefault();

In attachment there are example application.

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Aug 13 '10 at 07:40

pil0t's gravatar image


Fixed as well ;)

(Aug 13 '10 at 07:40) Alex Yakunin Alex%20Yakunin's gravatar image

One Answer:

Fixed, I'm closing the topic.

answered Sep 03 '10 at 16:25

Alex%20Yakunin's gravatar image

Alex Yakunin

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