LINQ to SAP SuccessFactors LMS Data
This article illustrates using LINQ to access tables within the SAP SuccessFactors LMS via the CData ADO.NET Data Provider for SAP SuccessFactors LMS. To achieve this, we will use LINQ to Entity Framework, which facilitates the generation of connections and can be seamlessly employed with any CData ADO.NET Data Providers to access data through LINQ.
See the help documentation for a guide to setting up an EF 6 project to use the provider.
- In a new project in Visual Studio, right-click on the project and choose to add a new item. Add an ADO.NET Entity Data Model.
- Choose EF Designer from Database and click Next.
- Add a new Data Connection, and change your data source type to "CData SAP SuccessFactors LMS Data Source".
Enter your data source connection information.
SAP SuccessFactors LMS uses OAuth authentication. Before connecting, you must configure an OAuth application tied to your SAP SuccessFactors LMS account.
To establish a connection, set the following properties:
- User: Your SAP SuccessFactors LMS username.
- CompanyId: Your SAP SuccessFactors company identifier.
- Url: The SAP SuccessFactors API URL (e.g., https://api4.successfactors.com).
- OAuthClientId: The client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The client secret assigned when you registered your custom OAuth application.
See the Getting Started chapter of the help documentation for a guide to creating a custom OAuth app and using OAuth.
Below is a typical connection string:
User=username;CompanyId=CompanyId;Url=https://api4.successfactors.com;InitiateOAuth=GETANDREFRESH;
- If saving your entity connection to App.Config, set an entity name. In this example we are setting SAPSuccessFactorsLMSEntities as our entity connection in App.Config.
- Enter a model name and select any tables or views you would like to include in the model.
Using the entity you created, you can now perform select commands. For example:
SAPSuccessFactorsLMSEntities context = new SAPSuccessFactorsLMSEntities();
var itemsQuery = from items in context.Items
select items;
foreach (var result in itemsQuery) {
Console.WriteLine("{0} {1} ", result.Id, result.ItemID);
}
See "LINQ and Entity Framework" chapter in the help documentation for example queries of the supported LINQ.