Vous êtes sur la page 1sur 3

T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center

25-May-15
Log In

Products

Free Trials & Demos

Buy

SUPPORT CENTER

Support
Tickets

My Account
Examples

About Us
Localization

Editing an XPO object in a separate Form in Server Mode

FAQ

Submit a Support Ticket

Type search string and press Enter

solution

Training Events

ID:
T210787

Tags: .NET, Frameworks (XAF & XPO), eXpress Persistent Objects

Created O n :
2/18/2015 2:12:34 PM

Mo dified O n :
3/11/2015 12:59:36 PM

Chris D 4 months ago

B u ild:
v2014 vo l 2.3 / 4-Dec-2014

[DevExpress Support Team: CLONED FROM T210099: How to synchronize XPServerCollectionSource with BindingContext?]
Furthermore, i really appreciate your help / advise:
This is my szenario:

Related Questions

I have a grid with 100.000 records. (servermode).


If I doubleclick on a row, i need to open a new form with this record in a datalayoutcontrol + some buttons / etc.
A possibilty to add a new record should also be forseen.

Ho w to view p ersisten t o b jects in


th e XtraG rid an d edit th em in a
sep arate w in do w

old szenario: No server mode, XPcollection, Custom-Editform (not everythings possible with editform), slow
new Szenario: Server Mode, new form for adding/editing, either linked by CurrencManager or (what do you think) by fetching the selected record again
with XPcollection on the new form (no server mode) and refreshing the grid after leaving the input form. Please feel free to comment, i really need your
input
Code:
on Doublecklick show the form: ff.ShowDialog(ID)

XPO -XAF-G RID Asyn c


XPServerCo llectio n So u rce,
G ridLo o kU p Edit, Server mo de
server mo de grid n o t editab le
(XPServerCo llectio n So u rce an d
O racle)

search the selected record inside the new form: XpCollection1.CriteriaString = "ID=" & id
Save the record after changes are made : Session1.Save(XpCollection1)
refresh the grid after leaving the form and hold the current row:

[VB.NET]

Open in popup window

W h at is th e b est w ay to ch an ge
O b jectClassIn fo fo r xp co llectio n at
ru n time
Sh o w Mo re

Dim i As Integer = GridView1.FocusedRowHandle


Dim top As Integer = GridView1.TopRowIndex
Session1.DropIdentityMap()
XpServerCollectionSource1.Reload()
GridView1.FocusedRowHandle = i
GridView1.TopRowIndex = top
What do you think ??
Thanks a lot.
[Updated]
Perfect, this is exactly the solution i want to go for !
Last question, how do you handle the add of a new recordset.
Grid.addnew is not the right one, because i have no rowid if i go to the edit form ?!
Thanks for your help !

Leave a Comment

1 Solution
0

Uriah (DevExpress Support) 4 months ago

You can simply pass to the edit form persistent object that you want to edit. I have attached a simple example illustrating this approach.
In the edit form I use the XPCollection with the LoadingEnabled property set to false. I do not need to load any objects, I just want to add a single object to
edit its properties. I also do not bind the XPCollection to the Session at design time. I do it at run time using the ResolveSession event. This trick helps me
bind the XPCollection to the Session instance related to the parent Form and avoid mixing different Sessions.
In the edit form constructor, I create the NestedUnitOfWork and use it to reload the object passed from the parent form. The purpose of the
NestedUnitOfWork in this example is to allow users to cancel changes without affecting objects in the parent form. If you want to learn more about nested
unit of work, refer to this article: Nested Units of Work.
When the user clicks the "Save" button in the edit form, I execute the CommitChanges method of the nested unit of work. This method update changed
objects in the parent Session. In other words, a corresponding record in the GridView will be automatically updated. You do not need to call the
XPServerCollectionSource.Reload method or use dirty hacks such as clearing the Session's identity map.
If the XPServerCollectionSource is bound to the Session instance, changes made in the edit form will be automatically saved to the database. If the
XPServerCollectionSource is bound to the UnitOfWork instance, you need to execute the CommitChanges method after the edit form is closed.
To add a new record, create a new persistent object instance and pass it to the edit form as a parameter. This time, however, you will need to reload the
XPServerCollectionSource, because the new object will not automatically appear in the grid. Executing the XPServerCollectionSource.Reload method will be
sufficient. Also, if you want to immediately display the added record to a user, use the GridView.LocateByValue method to obtain the handle of a row that
displays the new object and assign the result to the GridView.FocusedRowHandle property.
Attached is a sample project demonstrating how to implement this.
T210099VB.zip

Show all comments

Chris D 3 months ago


So , w e go t stu cked ?! Th e th in g is, my p ro cedu re is w o rkin g fin e, b u t i w o u ld like to fo llo w th e (yo u r) ru les an d h ave th is acco rate ru n n in g.

https://www.devexpress.com/Support/Center/Question/Details/T210787

1/3

T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center

25-May-15

O n e remake, th e ro u tin e (FLS_PO STEN w ill also w o rk w ith co n tacts, b u t n o t ch an gin g, ju st readin g)
If i u se
An y ideas ?

Uriah (DevExpress Support) 3 months ago


W h at is th e Sessio n field in th e co de sn ip p et ab o ve? If it is a U n itO fW o rk in stan ce, call Sessio n .Co mmitCh an ges() in stead o f v.Save() w h en
creatin g a VTSAU FTRAG _View in stan ce. In th is situ atio n , yo u w ill b e ab le to get a saved o b ject b y its key.
Ho w ever, I w o u ld su ggest yo u rew rite yo u r co de an d get rid o f u n n ecessary ro u n d trip s to th e server. Th e co de b elo w do es th e same as yo u r
co de, b u t do es n o t n eed to save th e VTSAU FTRAG _View in stan ce b efo re assign in g it to th e co n t.NU MB ER10 p ro p erty.

[VB.NET]

Open in popup window

Dim con_id As Integer = co.ID


If cONt.TEXT5 = "JA" And cONt.NUMBER2 > 0 Then
POSTEN(con_id) (external procedure which needs the saved record)
Else
If cONt.TEXT5 = "JA" And (cONt.NUMBER2 = 0 Or cONt.NUMBER2 = Nothing)
Then
cONt.NUMBER2 = (FLS_POSTEN(con_id))
cont.NUMBER10 = Session.GetObjectByKey(Of VTSAUFTRAG_View(Convert.ToDouble(cont.NUMBER2))
If IsNothing(cont.NUMBER10) Then
cont.NUMBER10 = New VTSAUFTRAG_View(Session)
cont.NUMBER10.NR = cont.NUMBER2
cont.NUMBER10.AENDERUNGSDATUM = Date.Now
End If

Chris D 3 months ago


in stead o f v.save
Yes, i tried th is, to o . I receive an erro r th at data are extern al ch an ged, lo ckin gexcep tio n ........

Chris D 3 months ago


Th is I receive:
Ein Ausnahmefehler des Typs "DevExpress.Xpo.DB.Exceptions.LockingException" ist in DevExpress.Data.v14.2.dll aufgetreten.
Zustzliche Informationen: Das Objekt kann nicht bestehend bleiben. Es wurde von einem anderen Programm modifiziert oder gelscht (bereinigt).
If i do th is: Me.Sessio n .Lo ckin gO p tio n = Lo ckin gO p tio n .No n e, I receive n o erro r, b u t th is seems to b e n o t th e righ t w ay.
Co u ld it b e p o ssib le, th at th e p ro b lem is th e IDENTITY server side field. W h at i reco gn ized is th at w h en i w o rk w ith sessio n o n ly, after save, my
ID (au to in cremen t) is filled in (co n .ID= 4711). If I w o rk w ith U O W , after co mmit, th e ID is still emp ty (clien t side), o n server side (sql) th e id is
filled.
I redu ced co de to mimimu m an d still receive th is lo ckin g erro r:

[VB.NET]

Open in popup window

Me.BindingContext(Me.XpCollection1).EndCurrentEdit()
Me.Session.CommitChanges()
Me.Session.BeginNestedUnitOfWork()
Dim cont As CONTACTS = Session.GetObjectByKey(Of CONTACTS)(co.ID)
cont.NOTES0 = "test"
Me.Session.CommitChanges()
Co u ld it b e th at U O W h as p ro b lems th ere (iden tity fields):

[SQL]

Open in popup window

[ID] [int] IDENTITY(1,1) NOT NULL,


? Ch ris

Uriah (DevExpress Support) 3 months ago


W e h ave discu ssed th is p ro b lem ab o ve an d I su ggested yo u do n o t u se th e NestedU n itO fW o rk, b ecau se in yo u r scen ario yo u can n o t avo id
mu ltip le co mmits. Can yo u co n firm th at Me.Sessio n is th e same in stan ce as th e Sessio n th at is u sed in th e p aren t Fo rm?
Have yo u tried th e co de I su ggested ab o ve? If it do es n o t w o rk, w o u ld yo u p lease clarify w h at do es n o t w o rk?

Show all comments

DEVEXPRESS
About Us
News
Our Awards
Upcoming Events
User Comments
Case Studies
Reviews and Publications
Licensing
Purchasing
MVP Program
Contact Us
Logos

.NET CONTROLS
WinForms
ASP.NET
MVC
WPF
Silverlight
Windows 8 XAML
CROSS PLATFORM
Reporting
Document Automation

Leave a Comment

MOBILE
DevExtreme Mobile

HTML5 JS WIDGETS
DevExtreme Web

ENTERPRISE TOOLS
Report Server
Analytics Dashboard

iOS 7
DataExplorer

FRAMEWORKS
eXpressApp Framework
CODE-DEBUG-REFACTOR
CodeRush for Visual Studio

FUNCTIONAL WEB TESTING


TestCafe
DELPHI C++BUILDER
VCL

SUPPORT
Search the Knowledge Base
My Questions
Code Examples
Getting Started
Demos
Documentation
Blogs
Training
Webinars
Current Version/Build
Version History

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

https://www.devexpress.com/Support/Center/Question/Details/T210787

2/3

T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center

25-May-15

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, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you
build and deliver your best in the shortest time possible.

Your Privacy - Legal Statements

https://www.devexpress.com/Support/Center/Question/Details/T210787

Copyright 1998-2014 Developer Express Inc.


All trademarks or registered trademarks are property of their respective owners

3/3