Problem
You want to persist your objects to a MS SQL Server database instead of the default access database
Solution
using System;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
class Program {
static void Main(string[] args) {
string conn =
MSSqlConnectionProvider.GetConnectionString(".",
"XPOCookbook");
XpoDefault.DataLayer =
XpoDefault.GetDataLayer(conn,
AutoCreateOption.DatabaseAndSchema);
}
}
Discussion
To connect to a SQL Server database, instead of the default Access database, the first thing that we have to do is to create the required connection string by calling the GetConnectionString() method on the MSSqlConnectionProvider class and passing in the server name and database name. Having thus obtained the connection string, we can then make our database the default one used by XPO by setting the XpoDefault DataLayer property to the result of calling the GetDataLayer() method, on the XpoDefault class, passing in the connection string and setting the AutoCreateOption.
Technorati tags:
XPO Cookbook