O'Reilly logo

Programming Atlas by Christian Wenz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Custom Data Source

If you want the full power of data access at your disposal and do not want to stick to the data structure provided by the data source, you can implement your data source by yourself, as a server-side ASP.NET class. Since Atlas relies heavily on web services, you have to implement a DataService class. The associated class is implemented in the Microsoft.Web.Services namespace. Within the DataService class, you have to implement the default methods for a data object: they are listed in the enumeration System.ComponentModel.DataObjectMethodType and include the following:

  • Delete

  • Insert

  • Select

  • Update

Displaying Data from a Custom Data Source

For demonstration purposes, we will first implement a web service SELECT method, which retrieves data from—you guessed it—the Purchasing.Vendors table in the AdventureWorks database.

You can, as before, implement a method that returns the desired data. By using the [DataObjectMethod(DataObjectMethodType.Select)] attribute, you declare the specific method as the “select” method. The actual naming of the method is arbitrary. As data type, you can again return a custom type, as shown in Example 9-5.

Example 9-5. Returning a custom type

ListViewVendorsDataServiceCustomType.asmx, excerpt
[DataObjectMethod(DataObjectMethodType.Select)] public Vendor[] GetVendors() { SqlConnection conn = new SqlConnection( "server=(local)\\SQLEXPRESS; Integrated Security=true; Initial Catalog=AdventureWorks"); conn.Open(); SqlCommand comm ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required