.NET QuickStart

10 minutes

InterSystems supports three lightweight .NET APIs that provide direct access to InterSystems IRIS® databases via relational tables, objects, or multidimensional storage.

.NET features available in InterSystems IRIS include:

  • Relational access through an ADO.NET API
  • Object access through the InterSystems XEP API
  • Access to multidimensional storage through the InterSystems Native API
  • Multi-model access to use multiple APIs together
  • Support for third-party APIs such as Entity Framework
  • An underlying consistent structure, avoiding data duplication

Feel free to watch the video or try the exercise below.

With .NET, you can interact with InterSystems IRIS relationally (with ADO.NET), using objects (with XEP or Entity Framework), or natively (with the Native API). In the steps below, you will access a set of sample stock data using each of the ways described.

Set up


  1. First, make sure you have an instance of InterSystems IRIS and a multi-language IDE ready to go. Sandbox settings will appear below after you log in and launch a sandbox.

    If you don’t have InterSystems IRIS yet, get a free, online development sandbox here. Log in with your InterSystems universal account, or register for one below.

  2. Clone the quickstarts-dotnet repo into the /home/project directory in the cloud IDE whose settings are above. Open the IDE . Then in the IDE’s terminal window:
    cd /home/project
    git clone -b try-iris http://github.com/intersystems/quickstarts-dotnet
    
  3. Using the Explorer pane (the file browser encompassing the left side of the IDE), open the quickstarts-dotnet folder. Then open the connections.config file and change the value of IP to (provision a sandbox to get this setting) and the value of port to (provision a sandbox to get this setting).

SQL-based access with ADO.NET

Use the standard ADO.NET API for SQL-based access to relational tables.

  1. In ADO folder, open adoNETplaystocks.cs to view the ADO.NET code. You will notice the connection string uses these variables to connect:
    connect.ConnectionString = "Server = " + ip + "; Port = " + port + ";
    Namespace = " + Namespace + "; Password = " + password + "; User ID = " + username;
    
  2. Run adoNETplaystocks.cs:
    cd /home/project/quickstarts-dotnet/ADO
    dotnet run
    
  3. This code simulates a stock trading application, allowing you to manage your personal portfolio and see how you would have done selling on a particular date.
    • Run option 1: View the top 10 stocks on 2016-08-12.
    • Run option 2: Create the Portfolio table.
    • Run option 3: Add three new portfolio items (for AMZN, GOOGL, and EQIX) using a value between the opening and closing price on 2016-08-12.
    • Run option 6: See how much you would have made on your portfolio if you sold on 2017-08-10.
    • Run option 7: Quit.

This code uses standard ADO.NET to create, read, update, and delete data within InterSystems IRIS. With the InterSystems IRIS driver, you can easily connect and use ADO.NET in the way you expect.

XEP for high performance inserts

Use XEP for high performance, real-time object insertions.

  1. In XEP folder, open xepplaystocks.cs to view the XEP code. You will notice the connection string uses these variables to connect:
    xepPersister.Connect(ip, port, Namespace, username, password);
  2. Run xepplaystocks.cs:
    cd /home/project/quickstarts-dotnet/XEP
    dotnet run
    
  3. This code simulates real-time stock trades.
    • Run option 1: Make a sample trade. For example, trade two shares on 2016-08-12 for $300/share, using your own name as the trader.
    • Run option 2: Save this trade.
    • Run option 3: Generate 500 generic trades.
    • Run option 4: Retrieve the trade objects from the database.
    • Run option 6: Update the names to prepend NYSE- to each stock name and retrieve the trade objects from the database again.
    • Run option 7: Quit.

With XEP, you can efficiently stores objects directly to InterSystems IRIS, requiring no translation to rows.

Native API to store and exercise a custom structure

Use the Native API to store to a custom structure and call InterSystems IRIS methods or routines.

  1. In Native API folder, open nativeplaystocks.cs to view the Native API code. You will notice the connection string uses these variables to connect:
    connect.ConnectionString = "Server = " + ip + "; Port = " + port + "; Namespace = " + Namespace
    + "; Password = " + password + "; User ID = " + username;
    
  2. Run nativeplaystocks.cs:
    cd /home/project/quickstarts-dotnet/NativeAPI
    dotnet run
    
  3. This code stores stock data in a custom data structure.
    • Run option 2: Store the stock data in a custom structure.
    • Run option 3: Retrieve and view the stock data from this custom structure.
    • Run option 4: Call population methods within InterSystems IRIS to generate better information for trades, as seen in the XEP example above.
    • Run option 5: Print the version of IRIS to the screen. This is retrieved by calling a routine within InterSystems IRIS.
    • Run option 6: Quit.

With the Native API, you can efficiently store data in your own custom data structure, allowing you to answer questions you could not answer using tables or objects. Additionally, you can call class methods and routines from within InterSystems IRIS using the Native API.

Use ADO.NET, XEP, and Native access side by side

Use ADO.NET, XEP, and Native access side by side, choosing the best model for each task.

  1. In the Multiplay folder, open multimodelplaystocks.cs to see how all APIs work together. You will notice the connection string uses these variables to connect:
    xepPersister.Connect(ip, port, Namespace, username, password);
    Notice this code connects using the XEP connection. Since EventPersister inherits from IRISConnection, all ways to connect leverage the same underlying connection to InterSystems IRIS.
  2. Run multimodelplaystocks.cs:
    cd /home/project/quickstarts-dotnet/Multi-model
    dotnet run
  3. This code stores information about the stocks of various companies.
    • Run option 1: Retrieve quickly all distinct stock names from the Demo.Stock table with ADO.NET.
    • Run option 2: Create objects and store them directly to the database with XEP, avoiding any translation back to tables.
    • Run option 3: Call population methods within InterSystems IRIS for founder and mission statement with the Native API.
    • Run option 4: Quit.

With InterSystems IRIS, you can use one connection, and use the method that is best for each task, decreasing the time it takes to develop your applications while also increasing your application performance. XEP efficiently stores objects directly to InterSystems IRIS, requiring no translation to rows. It is worth mentioning that ADO.NET can also be used to retrieve the data stored using XEP, reducing data redundancy.