eXpress App Framework Team

This Blog

XAF - 10 - Advanced data layer features

This is post no. 10 in the mini series "10 exciting things to know about XAF". You can find the announcement of the series here.

I've reached the last post in the mini series, and this is going to be about the functionality XAF inherits from the underlying infrastructure that our ORM product XPO provides. For a start, this is where XAF gets its compatibility with a vast number of different database systems from.

There are two different ways of changing the database type XAF connects to. The very easy approach, which we've implemented for a few of the most common backends, is to use the connection components in the Application Designer within Visual Studio. For backends that aren't directly supported by a connection type in the Designer, you must configure the connection string in the app.config and/or web.config file(s) manually.

Of course it is important to know what connection strings you need to use. Generally I guess if you're using a particular RDBMS, you are probably more familiar with the connection string format it uses than I am, so in reality it's probably not a big problem. Your RDBMS docs should give you details, as well as online sources like http://www.connectionstrings.com/. For the purpose of using the connection strings with XPO/XAF, there's one other thing that's important though: the connection string format must be recognizable by our libraries, so they know what database type to connect to. There's a pretty useful heuristics at work to figure this out, but sometimes connection strings look so similar that the distinction isn't easy.

For that reason, we have introduced a flag called "XpoProvider" into the connection string, which tells XPO explicitly which connection provider it has to use. The other extremely helpful thing is that all XPO connection providers have a helper method GetConnectionString, which takes a few typical parameters and generates a correct connection string, including the XpoProvider flag, for you. To take advantage of this, create a new Console Application project and add references to DevExpress.Data, DevExpress.Xpo and, if your provider is one of the less common ones, DevExpress.Xpo.<version>.Providers. The namespace DevExpress.Xpo.DB now has all the various Connection Provider classes, and you can output valid connection strings on the console like so:

Console.WriteLine(MSSqlConnectionProvider.GetConnectionString(".", "mydb"));
Console.WriteLine(MySqlConnectionProvider.GetConnectionString("localhost", "user", "password", "database"));
Console.WriteLine(PervasiveSqlConnectionProvider.GetConnectionString("localhost", "user", "password", "database"));

This example will render the following output:

 
XpoProvider=MSSqlServer;data source=.;integrated security=SSPI;initial catalog=mydb
XpoProvider=MySql;server=localhost;user id=user; password=password; database=database;persist security info=true;
XpoProvider=Pervasive;Server=localhost;UID=user;PWD=password;Data Source=database;

In addition to this, XPO also supports connecting to a service of some description, over a remote connection. Over time I've written a whole lot of blog posts on this topic, which I recommend you read if you're interested in this scenario. Here's the main XPO blog, which you should probably read through yourself. Here's an incomplete list of the interesting posts on the subject:

The connection strings that make XPO connect to XML Web Services and .NET Remoting are also supported by XAF directly.

Finally, if you want to influence the way the XPO connection is set up and do things you can't specify through the connection string, it is possible to hook into the process of setting up the XPO connection provider and data layer. To do this, you override the method OnCreateCustomObjectSpaceProvider in your WinApplication and/or WebApplication class(es) and return your own version of an ObjectSpaceProvider. It isn't hard to derive your own ObjectSpaceProvider from one of the standard ones and handle data layer creation in any way you see fit -- if there's interest in this and reading the source of ObjectSpaceProvider.cs doesn't help you, leave a comment and I'll try to create a sample when I have time.

Some other interesting features of XPO that you could enable or configure using this approach are the data layer caching and SqlDependency features. Of course you can switch on SqlDependency support by using the right XpoProvider flag, as described in the article, and this also enables data layer caching. But SqlDependency is a special feature for SQL Server support, and setting up data layer caching for other backends currently requires the OnCreateCustomObjectSpaceProvider approach outlined above.

So, that's all I have to say today. I hope the series was interesting -- I'll hand the post on styling ASP.NET applications in as soon as it makes sense, again my apologies for that one. I'm almost on my way to TechEd now -- if you're there, say hi!

Published May 31 2008, 04:35 PM by
Filed under:
Bookmark and Share

Comments

Greg Munn

"The connection strings that make XPO connect to XML Web Services and .NET Remoting are also supported by XAF directly"

Does this include WCF as well?  I've tried to implement WCF with XAF (8.1.x) and have not had a lot of success - I'd like to see an updated example that did this if that were possible.  The changes to XAF since the WCF sample was created leave me a little confused as to where and how to achieve this correctly.

Cheers,

Greg

June 1, 2008 6:10 AM

Binish Peter

I would like to see the example

reason: I have custom MSSqlConnectionProvider to use date manipulation features of SQL Server

June 2, 2008 9:15 AM

drew..

thank you Oliver.. it has been fun reading these posts.. hopefully there will be even more along similar tracks.. cheers!

June 3, 2008 3:16 PM

Sebastia Prat i Pons

Thanks Oliver, I'm using the publication service and works fine! It's a good approach for distributed aplications.

It will be really interesting to have new project in the solution (6) that deals with the remote data and help us to put the most critical remote BLogic processes to make the product more robust, like generating 800 invoices at once.

July 2, 2008 5:32 PM

Dan Arnold

"The connection strings that make XPO connect to XML Web Services and .NET Remoting are also supported by XAF directly."

For the life of me, this statement makes no sense.

XPO doesn't even support a connection string for a service based datastore.

Are you referring to the normal database connectionstring that is used in the Publication Serverice XML file?

If so, that, how is that a directly supported connection string that XAF understands?

I wish your component sources and XPCollection components wuld actuallytake a connectionstring the referred to a url, port and service name, and if it does, I'll be thrilled.

Please show me a connection string, as you decribe here, and where it is used in XAF directly.

Thanks,

Dan.

PS

Trying to learn to use your products is always hard due to the multitude of sources (fragmented help and documentation). I have and will continue to push DevExpress to not only provide hyperlinked help, which is impossible to print for offline use, bu to also provide DOCUMENTATION (NOT HELP FILES).

Otherwis we are faced with reading confusing blog entries that refer to olderblog entries or KB aticles that aren't always valid anymore.

Please excuse my off topic rant here...but also please hear what your customers are asking for.

July 27, 2008 2:43 PM

Oliver Sturm (DevExpress)

Dan,

As I say above, XPO supports all sorts of connection strings, and details are given on the pages linked from this article. In particular, an example for connections to web services is given on this page, also linked from the article above as the followup on the post "Using Web Services with XPO".

The post shows this example for a connection string that goes to a web service (and yes, it does contain URL, port and service name):

http://localhost:2224/XpoGate/Xpo.asmx

In XAF, you can use a connection string of this format (or any other format support by XPO) either in the XafApplication.ConnectionString property (that's the one that can be configured through the application designer in VS) and/or in the app.config/web.config files.

July 28, 2008 6:18 AM

Dan Arnold

Sorry I wasn't more specific. I have been using your XPOPublication service with an HTTP channel and binaryformatter (.net remoting)

I have been unable to get this to work by overriding OnCreateCustomObjectSpaceProvider.

Do you see anything wrong with the code ?

The service works fine with the Non-XAF application.

       protected override void OnCreateCustomObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args)

       {

           string url = @"dev/WindfallDataService.rem";

           IDataStore dataStore = WindfallObjectSpaceProvider.CreateInstance(url);

           args.ObjectSpaceProvider = new ObjectSpaceProviderSimple(new SimpleDataLayer(dataStore));

       }

   internal static class WindfallObjectSpaceProvider

   {

       internal static IDataStore CreateInstance(string url)

       {

           RegisterChannel();

           IDataStore dataStore = (IDataStore)Activator.GetObject(typeof(IDataStore), url);

           return dataStore;

       }

       private static void RegisterChannel()

       {

           BinaryClientFormatterSinkProvider clientSink = new BinaryClientFormatterSinkProvider();

           HttpChannel channel = new HttpChannel(null, clientSink, null);

           ChannelServices.RegisterChannel(channel, false);

       }

   }

July 28, 2008 1:28 PM

Sigurd Decroos

A very good sample (VB.Net if possible) would be very nice. All those words and links are nice for people with a lot of time to read. Persons like me need a clear example that speaks for itself and when we don't understand something, there's always the help or forum :)

August 3, 2008 4:45 PM

10 exciting things to know about XAF - eXpress App Framework Team

Pingback from  10 exciting things to know about XAF - eXpress App Framework Team

August 22, 2008 6:08 PM

Using XAF with Embedded Firebird « Development Technobabble

Pingback from  Using XAF with Embedded Firebird « Development Technobabble

February 27, 2010 3:09 AM

Marco Kummer

Hi Oliver

I currently have a customer where I need to use some form of XPO remoting. Right now I'm using the web service approach beacause it seemed the easiest to set up. However, my customer is having severe performance problems, even though the business objects aren't very complex.

Can you tell me which of the remoting methods would be the fastest (Web service, .NET remoting, WCF, RemObjects..) ? Or do you see any good way to speed up the web service approach?

Thanks a lot in advance!

Mrco

February 23, 2011 2:24 AM

Uriah (DevExpress Support)

I am afraid I do not have enough experience to share it with others. But probably, the following links will be useful for you:

msdn.microsoft.com/.../ms978411.aspx

msdn.microsoft.com/.../aa738737.aspx

February 23, 2011 9:34 AM
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners