Property changed event on refetch

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 19-Oct-2009 23:11:45   

When a new entity which exists in a Context is inserted into my database, the entity it refetched, which updates it's Primary Key value with a database-generated identity. My problem is the setting of this value is not causing a PropertyChanged event.

The application I am working on needs to be able to show this PK value to the user who will later use it for other things. The entity is shown in a grid which has, among other columns, an Id column, which is supposed to represent the primary key value of the entity in the grid's row. When I commit changes to the database, this Id column is not refreshed because the PropertyChanged event is not being raised.

I have a workaround at the moment by refreshing the binding on a save, but was wondering if this would be something that could possibly be worked into the entity base class code? Right now, it would only be helpful for me on in a refetch-on-save situation, but I could imagine that this would be an issue for any time even a normal fetch would happen for an entity existing in a Context.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Oct-2009 04:51:11   

So, you are using LLBLGen Context right? Could you please show the code snippet where you commit changes? What LLBLGen Pro Runtime Library version are you using? (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7722)

David Elizondo | LLBLGen Support Team
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 20-Oct-2009 18:38:40   

daelmo wrote:

So, you are using LLBLGen Context right? Could you please show the code snippet where you commit changes? What LLBLGen Pro Runtime Library version are you using? (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7722)

I'm using 2.6.9.511 Adapter.

Here is my commit...not really that interesting simple_smile


Dim unitOfWork As New UnitOfWork2()
Dim allEntities As ICollection(Of IBentekEntity) = GetAllEntities()
For Each entity As IBentekEntity In allEntities
      unitOfWork.AddForSave(entity, Nothing, True, True)
Next
For Each entity As IBentekEntity In _entitiesToDelete
       unitOfWork.AddForDelete(entity)
Next

unitOfWork.Commit(adapter)
_entitiesToDelete.Clear()

IBentekEntity is inherited from IEntity2. The adapter is passed in as an argument to the method that runs this code.

I am using the LLBLGen Context, yes. I think the issue is that on a refetch, the DataAccessAdapter just replaces the new Fields object inside the entity, and the entity itself is not replaced.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Oct-2009 06:30:46   

Just to understand, the entity is no new, and you somehow are updating its PK to another value (at db side)?

David Elizondo | LLBLGen Support Team
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 21-Oct-2009 20:52:52   

daelmo wrote:

Just to understand, the entity is no new, and you somehow are updating its PK to another value (at db side)?

No, the entity is new. It is being inserted and refetched on the insert. The primary key is set by the database, so the field value is changed by the refetch.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Oct-2009 06:36:16   

Oh, I understand now. See, the OnPropertyChange is used for edit cycles. In fact, before the entity is refetched, the PK is already there. So I think your workaround is ok.

David Elizondo | LLBLGen Support Team
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 22-Oct-2009 15:21:26   

daelmo wrote:

Oh, I understand now. See, the OnPropertyChange is used for edit cycles. In fact, before the entity is refetched, the PK is already there. So I think your workaround is ok.

That's what I figured. Thanks anyway.