DataAdapter.FetchEntityUsingUniqueConstraint

Posts   
 
    
BeauButton
User
Posts: 5
Joined: 13-Oct-2004
# Posted on: 19-Nov-2004 16:44:29   

Hello Everyone, I ran into a minor problem when using the FetchEntityUsingUniqueConstraint method of the DataProvider. I've read through the majority of the forum posts and i have not seen anyone post about this (nor did i find anything in the help document).

When i use FetchEntityUsingUniqueConstraint and a row that matches the constraint is found in the DataBase everything works fine. However if a row is not found that matches the constraint i get a "new" Entity (.IsNew = true), but when i attempt to use it in code i get an entity out of sync exception.

Is there something i need to do in order to use the "New" entity (it does not exist in the database and i do not want to save it immediately, only when the user clicks a save button). My work around for this has simply been to check ".IsNew", if it is true then i simply reinstantiate the entity.

Any insight would be great, i've got the solution working but i'd really like to know if there is something else i should be doing.

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Nov-2004 10:49:07   

new entities by design can't be used to read data from, as they don't exist yet. To ease development, a new entity is returned, not 'null'. To use it, you have to set values to it and save it. So you can better check if the method returns true (succeeded) or false (not succeeded). Based on that result, follow the path of creating a new instance or using the entity fetched.

Frans Bouma | Lead developer LLBLGen Pro
BeauButton
User
Posts: 5
Joined: 13-Oct-2004
# Posted on: 22-Nov-2004 17:42:06   

Thanks! Much Appreciated . . .