none
Try the new .QueryByCube() LINQ method RRS feed

  • General discussion

  • I just put online AdaptiveLINQ (www.adaptivelinq.com), a great component for LINQ developer.

    It add the .QueryByCube() extension method to IQueryable collections.

    Thus, you can do analytical query on your entity model.

    Sample :

    "sales per customer" will be written:

    myDataSet.QueryByCube(mySalesCube).Select(item => new {
        Customer = item.Customer,
        Sales = item.TotalSales
    });

    "sales per customer and category product" will be written:

    myDataSet.QueryByCube(mySalesCube).Select(item => new {
        Customer = item.Customer,
        Sales = item.TotalSales,
        Category = item.ProductCategory
    });

    The cube is defined using a high level designer integrated in Visual Studio.

    Dimensions and measures are defined as C# lambda expression.

    Please, send me any feedback.

    Monday, January 6, 2014 10:22 PM

All replies

  • Hello,

    What type is the mySalesCube parameter? And what type will the query return? IQueryable(), IEnumable() or IList()?

    Regards.

    Tuesday, January 7, 2014 5:25 AM
  • Hello,

    mySalesCube is an instance of class inheriting the AdaptiveLINQ.ICubeDefinition<TSource,TResult> interface.

    Sample :

    public class MySalesCube : ICubeDefinition<SalesOrderDetail,SalesCubeItem>
    {
    static readonly Expression<Func<SalesOrderDetail,string>> Customer = 
    orderDetail => orderDetail.SalesOrderHeader.Customer.Person.LastName;
    ...
    static readonly Expression<Func<IEnumerbale<SalesOrderDetail>,double>> TotalSales = 
    orderDetails => orderDetails.SalesOrderHeader.Sum(item => item.LineTotal);
    }

    Use the "cube designer" provided by AdaptiveLINQ Visual Studio extension to edit the MySalesCube class.
    (screen shoot here : http://www.adaptivelinq.com/learn)
    .QueryByCube<TSource,TResult>() result is an IEnumerable<TResult>.
    In fact the result is queryable, so you can write (for example) :
    .QueryByCube(mySalesCube).Where(cubeResultItem => cubeResultItem.TotalSales > 10000)

    Regards,

    Nicolas

    Tuesday, January 7, 2014 11:20 AM