示例#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);
        }