.NET QuickStart

10 minutes
estimated time of completion.
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). For this exercise, you can use your favorite IDE that supports .NET, such as Microsoft Visual Studio 2017. In the steps below, you will access a set of sample stock data using each of the ways described.
Note
If you don’t have InterSystems IRIS set up yet, get a free development sandbox here.

Setup

  1. Verify you have an instance of InterSystems IRIS, and an IDE that supports .NET (such as Microsoft Visual Studio 2017). If you are using AWS, Azure, or GCP, verify that you have followed the steps to change the password for InterSystems IRIS.
  2. Load sample stock data into InterSystems IRIS:
    1. Clone or download this repository: https://github.com/intersystems/Samples-Stock-Data. This repository has a folder named data, which contains all files needed to load the sample stock data.
    2. In the Management Portal, navigate to System Explorer > Classes and import DemoStockCls.xml and StocksUtil.xml files into the USER namespace from the data folder.
    3. In the InterSystems IRIS Terminal, type the following command. replace repo_home with the directory of Sample-Stock-Data repo that you recently cloned: do ##class(Demo.Stock).LoadData("repo_home/data/all_stocks_1yr.csv")
  3. To get the sample .NET code, download or clone the following repo into your IDE: http://github.com/intersystems/quickstarts-dotnet
    1. With Microsoft Visual Studio:
      • Select File > Open > Project/Solution. Choose the quickstarts-dotnet.sln file you recently cloned.
      • Select View > Solution Explorer to view project structure.
      • Right-click Solution. Select Add > Existing item. Choose config.txt.
      • Open config.txt file and modify the IP and password to be the correct values for your InterSystems IRIS instance. Port and username are most likely the defaults but you can verify those as well.
You should now have several classes for ADO.NET, XEP, Native API, and multi-model. Due to its complexity, Entity Framework requires separate set up for IDE and configuration files, which will be explained in detail in Step 6.

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. 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. 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.

  • 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;
  • Run nativeplaystocks.cs. 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 JDBC, XEP, and Native access side by side

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

  1. In the Multiplay folder, open multiplay.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 multiplay.cs. 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.

Use Entity Framework to store objects

Use Entity Framework, a third-party API, to store objects to InterSystems IRIS.
  1. In the Window directories:
    • Navigate to the folder you recently cloned. Then, go to EFPlay/IrisEF.
    • Add the IrisEF folder path into the system variables path. Details can be found here: Change the PATH system variable
    • Right-click setup.cmd and choose Run as Administrator.
    • Make sure Visual Studio is closed. Then, in Windows search, type Developer Command Prompt for VS2017. Right-click Developer Command Prompt for VS2017 > Run as Administrator and enter devenv /setup
  2. Open Microsoft Visual Studio. Inside the EFPlay folder, open App.config and modify the SERVER (IP) and password to be the correct values for your InterSystems IRIS instance. Port and user are most likely the defaults, but you can verify those as well. SERVER = "localhost"; port = 51773; NAMESPACE = "USER"; USER = _SYSTEM; password = SYS;
  3. Run Program.cs. This code stores stock data in a custom data structure.
    • Run option 1: Make a new trade for AMZN on 2016-08-12 with price: 200, # of shares: 2 and your own information as a new trader.
    • Run option 4: Find all traders with your last name.
    • Run option 5: View the leaderboard.
    • Run option 6: Quit.
With Entity Framework, you can connect to InterSystems IRIS using object-relational mapping. Entity Framework with InterSystems IRIS works exactly the way you expect, allowing you to easily upgrade your Entity Framework applications to work with InterSystems IRIS.