locked
Can I replace IQueryable<MonthlyBalance> query with generic list AsQueryable() in PreprocessQuery RRS feed

  • Question

  • Here is piece code I am trying to achieve

            partial void LastMonthlyBalanceByCustomerId_PreprocessQuery(int? CustomerId, ref IQueryable<MonthlyBalance> query)
            {
                MonthlyBalance lastMonthlyBalance = this.getCreateMonthlyBalanceByCustomer();
                List<MonthlyBalance> aMonthlyBalanceList = new List<MonthlyBalance>();
                aMonthlyBalanceList.Add(lastMonthlyBalance);
                query = aMonthlyBalanceList.AsQueryable();
            }

    If PreprocessQuery is not the place to do this, what are the other alternatives? 

    It should be common data requirements to return a specific set of entities based on powerful managed code linq query. The LightSwitch way to retrieve data is so limited, where is the extension points? If I have a set of entity I want to return to a query why LS stops me?


    jl

    Tuesday, December 3, 2013 11:59 PM

All replies

  • Should work. The following is from a system that gets a record from a User table based on the logged in user. It creates the row if it doesn't exist.

    // ----------------------------------------------------
    partial void xGetOrCreateCurrentUserRec_PreprocessQuery(ref IQueryable<User> query)
    {
        User userRec = null;
    
        using (this.Application.User.AddPermissions(Permissions.ServerUpdateOperation))
        {
            userRec = User.GetOrCreateUser(DataWorkspace, Application.Current.User.Name, Application.Current.User.AuthenticationType.ToString());   
        }
        if (userRec == null)
        {
            throw new Exception("GetOrCreateCurrentUserRec_PreprocessQuery() error: Failed to get or create User record.");
        }
        
        List<User> ret = new List<User>() { userRec };
        query = ret.AsQueryable();
    
    }


    Bruce

    • Proposed as answer by bruce demoose Tuesday, January 7, 2014 3:49 PM
    Tuesday, January 7, 2014 3:48 PM
  • After installing VS 2013 Update 1 and Office Developer Tools March 2014 Update this no longer works.

    Instead of:

    List<User> ret = new List<User>() { userRec };
    query = ret.AsQueryable();

    I now do:

    query = query.Where(x => x.Id == userRec.Id);

    It seems like with every upgrade, there is a change to some basic functionality that breaks something. I'm wondering if Lightswitch will ever become stable.


    Bruce

    Thursday, March 20, 2014 5:04 PM
  • After installing VS 2013 Update 1 and Office Developer Tools March 2014 Update this no longer works.

    Instead of:

    List<User> ret = new List<User>() { userRec };
    query = ret.AsQueryable();

    I now do:

    query = query.Where(x => x.Id == userRec.Id);

    It seems like with every upgrade, there is a change to some basic functionality that breaks something. I'm wondering if Lightswitch will ever become stable.


    Bruce

    Bumping this as I just tried something similar and confirmed this doesn't work. LightSwitch's bugs are incredibly frustrating.
    Friday, January 8, 2016 4:20 PM
  • I'm not on a machine where I can try it, but does something like this work?

    List<SomeEntity> myList = new List<SomeEntity>();
    
    myList = this.DataWorkspace.ApplicationData.SomeEntities.Execute().ToList();
    
    // or
    // myList = this.DataWorkspace.ApplicationData.SomeEntities.GetQuery().Execute().ToList();
    
    query = myList.AsQueryable();

    Friday, January 8, 2016 10:13 PM