For a while i had thought about doing a quick start guide for XPO as i went through the same thing you did as well. DevExpress documentation is nice but it is a TON of information to sift through. There isn't really any quick start guide to XPO per-say...maybe i'll write my first article finally.
I am going to make a few assumptions here, like you are using sql server as your backend.
One thing to keep in mind, if you are doing this/will ever get into using XPO with web applications you want to make sure EVERY SINGLE CALL you make using XPO is wrapped in a using(var uow = new UnitOfWork(), otherwise you get some nasty cross threading errors.
I use "YourClassName" in my examples. That is going to be your XPO objects that you either generate using the DevExpress ORM wizard or whatever it is you create by hand.
If you've got any other questions about xpo feel free to reach out to me.
Session session = new Session();
XpoDefault.DataLayer = XpoDefault.GetDataLayer(MSSqlConnectionProvider.GetConnectionString("YourServerHostnameOrIP", "DB Username", "DB Password", "DB Name"), AutoCreateOption.None);
XpoDefault.Session = session;
using (var uow = new UnitOfWork())
{
XPCollection<yourclassname> getRecords = new XPCollection<yourclassname>(uow);
foreach (var item in getRecords)
{
}
}
using (var uow = new UnitOfWork())
{
XPCollection<yourclassname> getSpecificRecord = new XPCollection<yourclassname>(uow, CriteriaOperator.Parse("Id = '1'"));
YourClassName getSingleRec =
new XPCollection<yourclassname>(uow, CriteriaOperator.Parse("Id = '1'")).FirstOrDefault();
}
using (var uow = new UnitOfWork())
{
XPCollection<yourclassname> getRecords = new XPCollection<yourclassname>(uow, CriteriaOperator.Parse("FileName LIKE '%user%'"));
foreach (var item in getRecords)
{
}
}
using (var uow = new UnitOfWork())
{
YourClassName save = new YourClassName(uow);
save.FieldName = "I am a value to save to Database";
save.Save();
uow.CommitChanges();
}
using (var uow = new UnitOfWork())
{
YourClassName update = uow.FindObject<yourclassname>(CriteriaOperator.Parse("Id = '1'"));
update.FieldName = "Update To New Value";
update.Save();
uow.CommitChanges();
}
</yourclassname></yourclassname></yourclassname></yourclassname></yourclassname></yourclassname></yourclassname></yourclassname>