Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid expression _.Key.Year #294

Open
dheenag opened this issue Jan 29, 2014 · 3 comments
Open

Invalid expression _.Key.Year #294

dheenag opened this issue Jan 29, 2014 · 3 comments

Comments

@dheenag
Copy link

dheenag commented Jan 29, 2014

Hi,
i am using BLToolkit.3.dll latest one.

I am getting error while grouping by Month and Year like Invalid expression _.Key.Year and Invalid expression _.Key.Month. how to fix that

this is my samples

 var q = (from ord in ctx.Orders_Infos 
                            group ord by new {Month=ord.ReleaseDate.Value.Month, Year=ord.ReleaseDate.Value.Year } into grp
                            select new
                            {
                                Total = grp.Sum(_ => _.Total),                               
                                year=grp.Key.Year,
                                month=grp.Key.Month
                            }).ToList();

how to fix or any other way to achieve that .

this is the Stack trace

[LinqException: Invalid expression _.Key.Year]
   BLToolkit.Data.Linq.Builder.SelectContext.GetMemberExpression(Expression newExpression, Expression expression, Int32 level) +1043
   BLToolkit.Data.Linq.Builder.SelectContext.BuildExpression(Expression expression, Int32 level) +3261
   BLToolkit.Data.Linq.Builder.PassThroughContext.BuildExpression(Expression expression, Int32 level) +51
   BLToolkit.Data.Linq.Builder.SelectContext.<BuildExpression>b__6(IBuildContext ctx, Expression ex, Int32 l) +40
   BLToolkit.Data.Linq.Builder.SelectContext.ProcessScalar(Expression expression, Int32 level, Func`4 action, Func`1 defaultAction) +574
   BLToolkit.Data.Linq.Builder.SelectContext.BuildExpression(Expression expression, Int32 level) +1624
   BLToolkit.Data.Linq.Builder.SelectContext.<BuildExpression>b__6(IBuildContext ctx, Expression ex, Int32 l) +40
   BLToolkit.Data.Linq.Builder.SelectContext.ProcessScalar(Expression expression, Int32 level, Func`4 action, Func`1 defaultAction) +1151
   BLToolkit.Data.Linq.Builder.SelectContext.BuildExpression(Expression expression, Int32 level) +1624
   BLToolkit.Data.Linq.Builder.GroupByContext.BuildExpression(Expression expression, Int32 level) +273
   BLToolkit.Data.Linq.Builder.SelectContext.BuildExpression(Expression expression, Int32 level) +1774
   BLToolkit.Data.Linq.Builder.<>c__DisplayClass55.<BuildExpression>b__54(Expression pi) +742
   BLToolkit.Linq.ExpressionHelper.Convert2(Expression expr, Func`2 func) +3529
   BLToolkit.Linq.ExpressionHelper.Convert2(IEnumerable`1 source, Func`2 func) +327
   BLToolkit.Linq.ExpressionHelper.Convert2(Expression expr, Func`2 func) +4527
   BLToolkit.Data.Linq.Builder.ExpressionBuilder.BuildExpression(IBuildContext context, Expression expression) +132
   BLToolkit.Data.Linq.Builder.SelectContext.BuildExpression(Expression expression, Int32 level) +711
   BLToolkit.Data.Linq.Builder.SelectContext.BuildQuery(Query`1 query, ParameterExpression queryParameter) +47
   BLToolkit.Data.Linq.Builder.ExpressionBuilder.Build() +823
   BLToolkit.Data.Linq.Query`1.GetQuery(IDataContextInfo dataContextInfo, Expression expr) +747
   BLToolkit.Data.Linq.ExpressionQuery`1.GetQuery(Expression expression, Boolean cache) +143
   BLToolkit.Data.Linq.ExpressionQuery`1.Execute(IDataContextInfo dataContextInfo, Expression expression) +39
   BLToolkit.Data.Linq.ExpressionQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +65
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +7675130
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +61
@igor-tkachev
Copy link
Owner

Try the latest.

@dheenag
Copy link
Author

dheenag commented Jan 30, 2014

Hi,

I am using the Latest dll but what happen when i apply like this

 var q = (from ord in ctx.Orders_Infos 
                            group ord by new {ord.CustomerId} into grp
                            select new
                            {
                               grp
                            }).ToList();

after that again i need to write query by group with month and year it comes with out issue but while applying directly group by month and year it will give an error.

ili added a commit that referenced this issue Feb 19, 2015
ili added a commit that referenced this issue Feb 19, 2015
@ili
Copy link
Collaborator

ili commented Feb 19, 2015

yah now it works, but subquery is generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants