Browse DevX
Sign up for e-mail newsletters from DevX


Meet the Future of Data Head-on with Comega : Page 2

Take a peek inside the research labs of Microsoft to see the future of data integration in programming languages.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Putting it Together in a Simple Application
The source code download has the full code for this sample article, or you can step through what's covered here. The first thing that you need to understand when building a database application is that Comega can take the metadata from a database into a managed assembly using the Sql2Comega.exe tool that is in the BIN directory of the Comega install. You'll see how this helps you in a moment. First, create a new 'Northwind' Comega application, and follow the instructions in the comments at the top of the generated code. This will get the Northwind connection working using the Sql2Comega tool mentioned earlier. Next, add a new class called 'GetData' to the project.

The entire GetData file is shown in Listing 2.

Change the output type for the project from Console Application to Class Library. You do this by right-clicking on the project in solution explorer, selecting properties, and then selecting 'General' under 'Common Properties'. On the right-hand side you set the project Output. (See Figure 2.)

If you compile your project now, a DLL assembly will be created for you.

Author's Note: Sometimes you will get strange database errors when compiling this (and other) Comega applications. If you encounter these, regenerate the Northwind reference as you did earlier, and try again. If that fails, close Visual Studio, then reopen it and compile again. This software is not a release software, so bugs are inevitable.

You can now consume this assembly within a traditional C# application. Create a new C# Web service and create a reference to the DLL. Note that you cannot create a multi-project solution, mixing C# and Comega in the current version. When you have referenced this DLL, add the following Web method to your application.

[WebMethod] public string getData() { ComegaGetData.DataBlock[] x = new ComegaGetData.DataBlock[32]; x.Initialize(); ComegaGetData.GetData dService = new ComegaGetData.GetData(); try { x = dService.getData(); } catch (Exception e) { Console.Write(e.Message); } return "Hello"; }

Figure 2. Setting the Output Type for a Project: The right column in this table allows you to change many properties of your project. In this case, change the output type to Class Library.
This will consume your Comega content classes (the DataBlocks) and load them into an array for C# to use. You can access the data using (for example) the following syntax. You can see (thanks to the struct) that it is strongly-typed.


The method just returns 'Hello' when it is done—you could extend it to process the data, now stored in X as you see fit.

This article gave you a whistle-stop tour of some of the features of Comega, and showed you how to build Comega applications today that may be consumed by your front-end applications built in traditional C# or VB.NET. The examples clearly show the power of the language, but have barely scratched the surface of what is possible. Use the techniques shown here to start using Comega meaningfully today to build a data layer into your applications. This is an excellent and innovative language that has a bright future and it will be very interesting to see it unfold and evolve. It isn't likely to hit the mainstream for some time yet—probably not until C# version 3 at the earliest—but you can use it today!

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date