The sample code is located in the installation directory in theLINQTable directory

Following up on the previous section, a search mask now opens up for the selection of tables. Take the desired table by confirming your selection with OK.


After the desired table has been selected, the following selection dialog will open. Here you check off the desired columns that are to be made available later on in the query output. You can also change the name of the proxy class that is internally generated. By default, the names of the columns correspond with the properties of the proxy class later on. You can name them yourself by writing over the entry in the Member column.


Confirm this by clicking OK. Now you’ll see a corresponding icon in the Designer. Save the .erp file in order to trigger the proxy classes code generation in the background. Experienced users can have a closer look at the implicitly generated file .Designer.cs/vb which shows how LINQ logic is mapped to traditional ERPConnect logic.


To now access the LINQ-capable class in the code, the data context first has to be instantiated. This is either done by entering the user name and password (with the previously stored system parameters) or alternatively entering the entire registration information (the constructor of the DataContext class is accordingly overloaded; alternatively, if you already know the R3Connection object, it can be addressed directly via the DataContext.Connection). With DataContext, the corresponding LINQ queries can be formulated:

Click to open C# example.
static void Main(string[] args) 
   SAPContext sc = new SAPContext("TestUser", "SECRET01"); 
   var MyTexts = from t in sc.MAKTList 
             where t.MATNR.StartsWith("100") 
             && t.SPRAS == "D" 
             select t; 
   foreach (var MyText in MyTexts) 
      Console.WriteLine(MyText.MATNR + " " + MyText.MAKTX); 
   Console.WriteLine("Press any key to exit"); 
Click to open VB example.
Sub Main() 
   Dim sc As New LINQTable.SAPContext("TestUser", "SECRET01") 
   Dim MyTexts = From t In sc.MAKTList _ 
            Where t.MATNR.StartsWith("100") _ 
            And t.SPRAS = "D" 
   For Each MyText In MyTexts 
      Console.WriteLine(MyText.MATNR & " " & _ 
   Console.WriteLine("Press any key to exit") 
End Sub