LLBLGenProDataSource and detailsview

Posts   
 
    
Kjelli
User
Posts: 27
Joined: 11-May-2006
# Posted on: 26-Sep-2006 12:39:28   

When inserting using LLBLGenProDataSource I have trouble getting the new id (of type Guid / newsequentialid).

-Using selfservicing, September 13/06 build. -The DataKeyNames parameter of the control is set. -SqlServerDQECompatibilityLevel = 2 in web config. -This is a custom control and there exists no html markup, all is done through code-behind.

I hook into DetailsView.ItemInserted to check the values, but the db key column is null in the values collection.

I just checked using new entity() and .Save(). This way the key is returned immediately.

The entity discussed is a subtype in a target per entity hierarchy.

Am I missing something?

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 26-Sep-2006 18:13:33   

Hi,

Do you use live persistance? Did you make sure the entity gets indeed inserted in the dbase? Are you sure the corresponding EntityField is null, or is it just the DetailsView column, which does not get updated?

Kjelli
User
Posts: 27
Joined: 11-May-2006
# Posted on: 27-Sep-2006 09:10:06   

I use livepersistence and the item gets inserted into the db.

I'm not sure how to get the newly inserted entity so I've only checked the detailsview and DetailsViewInsertedEventArgs.

How can I get the new entity?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 27-Sep-2006 09:53:48   

If you want the new entity, use LivePersistence set to false and hook a small piece of code to the PerformWork and PerformSelect statements. These can be one-liners really, as all parameters you've to pass are in the eventargs.

In the PerformWork, you'll receive a unitofwork which contains the changed/new entities to persist. You can grab them from the unitofwork and after commit you can grab the entities and the PK value.

Be aware that the entity instance itself is gone after the postback: the datasourcecontrol will refetch the data afterwards.

Frans Bouma | Lead developer LLBLGen Pro
Kjelli
User
Posts: 27
Joined: 11-May-2006
# Posted on: 27-Sep-2006 10:59:11   

Do i need to implement the PerformGetDbCount event as well (how?) ?

This is what I did after your response:


        void ds_PerformSelect(object sender, PerformSelectEventArgs e)
        {
            e.ContainedCollection.GetMulti(e.Filter, -1, e.Sorter, e.Relations, e.PrefetchPath);
        }

        void ds_PerformWork(object sender, PerformWorkEventArgs e)
        {
            e.Uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
        }

Is that all that's needed? It seems to be working all right so far.

I was comfortable using the livepersistence = true thing. I would appreciate a way to get the new identifier that way, perhaps in the DetailsView ItemInserted event. Are you sure that's not possible? The item is supposed to have been written at that point.

EDIT: I was kinda quick in my response rage I found the new identifier while debugging, but the property I used is not public. In fact there are no public properties on the UoW object. So the question still remains, how can I get the identifier (in the performwork event)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 27-Sep-2006 11:56:29   

Kjelli wrote:

Do i need to implement the PerformGetDbCount event as well (how?) ?

Only if you're using paging.

you then should do something like: e.DbCount = <select db count from db here>

This is what I did after your response:


        void ds_PerformSelect(object sender, PerformSelectEventArgs e)
        {
            e.ContainedCollection.GetMulti(e.Filter, -1, e.Sorter, e.Relations, e.PrefetchPath);
        }

        void ds_PerformWork(object sender, PerformWorkEventArgs e)
        {
            e.Uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
        }

Is that all that's needed? It seems to be working all right so far.

I was comfortable using the livepersistence = true thing. I would appreciate a way to get the new identifier that way, perhaps in the DetailsView ItemInserted event. Are you sure that's not possible? The item is supposed to have been written at that point.

yes, but it's not the concern nor the goal of the datasourcecontrol to do all kind of housekeeping jobs some control has to do nor can it possibly offer functionality to work with every control out there which needs special attention: it simply does what it should do: act when any of the Execute* methods is called. That's it. It can't do more.

EDIT: I was kinda quick in my response rage I found the new identifier while debugging, but the property I used is not public. In fact there are no public properties on the UoW object. So the question still remains, how can I get the identifier (in the performwork event)?

To get the entities which are about to be saved in a unitofwork: e.UoW.ConstructSaveProcessQueues(); List<ActionQueueElement<IEntity>> insertQueue = e.UoW.GetInsertQueue(); List<ActionQueueElement<IEntity>> updateQueue = e.UoW.GetUpdateQueue();

the entities to update/insert are in the actionqueueelement objects in the queues returned. In most cases, there won't be more than 1 entity to save.

Frans Bouma | Lead developer LLBLGen Pro
Kjelli
User
Posts: 27
Joined: 11-May-2006
# Posted on: 27-Sep-2006 12:42:45   

Thank you!

It's working now.