I have just started a new role as Junior developer using C# and Visual Studio 2012. I only found that my company use DevExpress Xpress Persistent Object (ORM) for Data Access when I joined them last week. This is new to me and I have been teaching myself how to use it using the devExpress documentation website
here
.
The problem is the documentation contains loads of information that I do not need at the moment because I need something to get me running ASAP. I have spent a lot of time searching for tutorials on google but nothing good shows up. Does any one know of any tutorial link that can get me building projects rightaway using DevExpress XPO?.
Anyhelp or suggestions will be highly appreciated.
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
>
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Do you have the code behind in XAF you can share? I'm sure if you can access the code you can massage the answer into your XAF code.