Best Pattern for edit Entity in new Window

Posts   
 
    
daycrom
User
Posts: 18
Joined: 04-Dec-2007
# Posted on: 07-May-2008 21:51:52   

LLBLGen v2.5 - Adapter

Hello!!!

I am working with a window that displays a list of Clients in a gridview, and when desire edit a record, open a new window with the detail of each field of the record selected.

Today, when I select a record in the gridview, I call a function that takes the selected ClientEntity (ListClientsBS.CurrentRow) and clone this(use memoryStream). This new entity cloned is sent to the new edition window, and once the edition is finally and save, a series of actions (agent events) reflect this change in the gridview (even if add one new ClientEntity).

This works perfect and allows me to work without reflect changes in the gridview at editing fields in detail view (or even if I cancel edition) until i save changes.

This I did to avoid refetch individual entities since the database (simply taken one from the list and the showed locally), but now that I am testing with large amounts of data, I see that the cloned by means of memoryStream consumes much memory because I read the graph complete and is slow (more than refetch an entity from the server).cry

The question is, which is the method that use you or which is the most suitable for this type of scenarios?

The idea was not consume network resources, but perhaps more expensive clone entities to bring some simple data from the network. The implementation would be conducted in an local client server environment , nothing of distributed scenarios or remote or connected/disconnected.

For now I am occur two ideas: ** 1- Take the Id of the entity selected, pass the Id at the view of edition and refetch the entity from the database with all their relations. (Simple code, but refetch one existent entity)

2- Clone each field of entity individually (Client.Fields.Cone; Client.Order.Field.Clone; etc.) (disadvantage: more code and checks of invalidity for each relationship). **

Thank you and I hope their view points and contributions.

Regards!!!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-May-2008 04:47:48   

Why clone the entity? Why not pass it across the new window. For example:

MyEditForm editForm = new MyEditForm(theEntityToEdit);
editForm.ShowDialog();

Are you using Winform's BindingSource control? This often facilitates the things.

David Elizondo | LLBLGen Support Team
daycrom
User
Posts: 18
Joined: 04-Dec-2007
# Posted on: 08-May-2008 05:44:50   

daelmo wrote:

Why clone the entity? Why not pass it across the new window. For example:

MyEditForm editForm = new MyEditForm(theEntityToEdit);
editForm.ShowDialog();

Are you using Winform's BindingSource control? This often facilitates the things.

Daelmo,

The Client Entity that want pass to new window is selected from a Collection of Client entities. This collection is linked to a gridview.

If I pass the entity from the collection directly , any change you make in some field of the new window, will be reflected in real time in the gridview without having saved the changes, and this is not desirable.

This is why need to create a new entity, either cloning or refetching.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 08-May-2008 09:14:35   

Isn't it better to just pass the PK to the new window and re-fetch the entity there. At least that's what I normally do.

Single entity fetches is not costy by all means.

daycrom
User
Posts: 18
Joined: 04-Dec-2007
# Posted on: 08-May-2008 10:40:46   

Walaa wrote:

Isn't it better to just pass the PK to the new window and re-fetch the entity there. At least that's what I normally do.

Single entity fetches is not costy by all means.

Walaa, I think there is a translation error in

Isn't it better to just pass the PK to the new window and re-fetch the entity there

I believe that wanted say that it was better to just pass the PK to the new window and re-fetch the entity there (The answer init with Isn“t)

Confirm please to make sure you understand.

Regards!!!!

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 08-May-2008 14:22:35   

Isn't it better to just pass the PK?

I ment it as a question, which means I do think it's better to pass the PK, don't you think so?

I missed the question mark simple_smile

In my solution, I always pass the PK in situations like this.