Пример #1
0
        static void Main(string[] args)
        {
            var nwind = new NorthwindContext();
            var loggerFactory = (nwind as IInfrastructure<IServiceProvider>).GetService<ILoggerFactory>();
            loggerFactory.AddConsole(LogLevel.Verbose);

            Submission2.GroupWithLet(nwind);
        }
Пример #2
0
        public static void GroupByNestedProp(NorthwindContext nwind)
        {
            // BUG throws "Sequence contains more than one element"

            var q = from p in nwind.Products
                    group p by p.Category.CategoryName;

            q.ToArray();
        }
Пример #3
0
        public static void GroupWithLet(NorthwindContext nwind)
        {
            // BUG throws "Expression of type '...' cannot be used for parameter of type '...' of method '...'"

            var q = from p in nwind.Products
                    let cat = p.CategoryID
                    group p by cat;
                    // group p by p.CategoryID; // - also fails when 'let' is present

            q.ToArray();
        }
Пример #4
0
        public static void GroupingAndNavigationWhere(NorthwindContext nwind)
        {
            // INFO "Support translating of GroupBy() to SQL" https://github.com/aspnet/EntityFramework/issues/2341
            // INFO "GroupBy throws NRE when grouping using navigation properties" https://github.com/aspnet/EntityFramework/issues/3626

            // BUG throws "Expression of type '...' cannot be used for parameter of type '...'

            var q = from o in nwind.Orders
                    where o.Shipper.CompanyName == "Speedy Express"
                    group o by o.OrderDate;

            q.ToArray();
        }
Пример #5
0
        public static void DateConst(NorthwindContext nwind)
        {
            var dataParam = Expression.Parameter(typeof(IQueryable<Order>), "data");
            var itemParam = Expression.Parameter(typeof(Order), "i");

            Expression query = dataParam;

            var whereClause = Expression.Lambda(
                Expression.MakeBinary(
                    ExpressionType.Equal,
                    Expression.PropertyOrField(Expression.PropertyOrField(itemParam, "OrderDate"), "Value"),
                    Expression.Constant(new DateTime(1998, 5, 6))
                ),
                itemParam
            );

            query = Expression.Call(typeof(Queryable), "Where", new[] { typeof(Order) }, query, whereClause);
            query = Expression.Call(typeof(Queryable), "Count", new[] { typeof(Order) }, query);

            Expression.Lambda(query, dataParam).Compile().DynamicInvoke(nwind.Orders);
        }