First define the schema updates that you would like to perform.
When modifying the size of a string column you need to do absolutely nothing. Xpo.UpdateSchema will examine your existing database and the XPO Size attribute and modify those columns without any intervention on your part.
To rename a column you would decorate the field or property with a RenameColumn attribute. The parameter identifies the previous name of the column.
private int renameMe;
[RenameColumn("OldColumnName")]
public int RenameMe
{
get { return renameMe; }
set { SetPropertyValue("RenameMe", ref renameMe, value); }
}
To delete a column you would decorate the class with a DeleteColumn attribute. The parameter identifies the name of the column to be deleted.
[DeleteColumn("DeleteMe")]
public class DeleteColumns : XPObject
{
}
All of the functionality of Xpo.UpdateSchema is accessed through an instance of the UpdateSchema class. Pass the connection string in the constructor of the UpdateSchema class. The connection string is the same one that you would use to connect an XPO DataLayer or Session.
using(UpdateSchema updateSchema = new UpdateSchema(
MSSqlConnectionProvider.GetConnectionString(
"MyServerAndInstance", "MyDatabase")))
{
//...
}
Next, call the UpdateSchema.Update method. Just like the Xpo.Session.UpdateSchema method, pass in the assembly, list of assemblies or list of types in which your persistent classes are contained.
bool result = updateSchema.Update(Assembly.GetAssembly(typeof(MyPersistentClass)));
bool result = updateSchema.Update(new Type[] {
typeof(MyPersistentClass), typeof(MyOtherPersistentClass) });
Xpo.UpdateSchema will process all of the modifications to your database as well as calling XPO to add new tables and columns to the persistent data store.