There are three attributes used to map linq queries to Tabular tables, columns and measures. We might also add mapping for alternative relationships as well.

Columns are mapped with:


     [AttributeUsage(AttributeTargets.Property)]
     public class TabularMappingAttribute : System.Attribute

The attribute constructor takes the actual database name of the column and the name of the table to wich it belongs.
This is used as


    public class X 
    {
     
      [TabularMapping("'Customer'[Title]", "Customer")]
       public String Title {get; set;}
     
    }


Tables are mapped with:


      [AttributeUsage(AttributeTargets.Class)]
       public class TabularTableMappingAttribute : System.Attribute


For example:


      [TabularTableMapping("'Currency'")]
      public class Currency : ITabularData 


Note that table classes should implement the ITabularData interface, that is an empty interface used only to discriminate the types that are mapping of tables, this interface may be removed in the future, since it is kind of redundant.

Measures are mapped to functions, methods with:


     [AttributeUsage(AttributeTargets.Method)]
      public class TabularMeasureMappingAttribute : System.Attribute


Shown in the following example:


       [TabularMeasureMapping("[Total Sales]")]
       public Decimal TotalSales()
       {
		throw new NotImplementedException("This method is only available in a LinqToDAX Query");
       }
       [TabularMeasureMapping("[Total Sales]")]
       public Decimal TotalSales(bool filter)
       {
		throw new NotImplementedException("This method is only available in a LinqToDAX Query");
       }

See the AdventureWorks project for complete example.

We plan to create a template/extension for Visual studio that will help you generate entities for your linq queries

Last edited Apr 28, 2014 at 11:48 AM by gyfarkas, version 3