Insert Fails using FormView and LLBLGenProDataSource

Posts   
1  /  2
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39896
Joined: 17-Aug-2003
# Posted on: 09-Jan-2007 09:54:20   

An example of that:


    /// <summary>
    /// Eventhandler for the PerformWork event on the _OrderDS datasourcecontrol
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void _OrderDS_PerformWork(object sender, PerformWorkEventArgs2 e)
    {
        // as we're using a formview, there's just 1 entity in the UoW.
        OrderEntity entityToProcess = null;
        List<UnitOfWorkElement2> elementsToInsert = e.Uow.GetEntityElementsToInsert();
        if(elementsToInsert.Count > 0)
        {
            // it's an insert operation. grab the entity so we can determine the PK later on. 
            entityToProcess = (OrderEntity)elementsToInsert[0].Entity;
        }
        using(DataAccessAdapter adapter = new DataAccessAdapter())
        {
            e.Uow.Commit(adapter, true);
        }
        if(entityToProcess != null)
        {
            // store the PK values so a redirect can use these. 
    
            _pkValuesAfterInsert = "&OrderId=" + entityToProcess.OrderId;
        }
    }

this is adapter, but you get the idea.

Frans Bouma | Lead developer LLBLGen Pro
JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 09-Jan-2007 17:16:37   

I get the idea and have almost got it.
If I am using self servicing and not adapter. transaction in the following code?

Dim transaction As ITransaction = new ???? e.Uow.Commit(transaction, true)

Thanks Jeff

I did try DAOClass objects.

JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 09-Jan-2007 18:32:46   

Disregard last message I have It working to insert data to DB again using the Adapter methods instead of Self servicing.

But can not figure out how to implement the performSelect method.

Sorry Thanks Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39896
Joined: 17-Aug-2003
# Posted on: 09-Jan-2007 19:27:25   

JeffM wrote:

Disregard last message I have It working to insert data to DB again using the Adapter methods instead of Self servicing.

But can not figure out how to implement the performSelect method.

Sorry Thanks Jeff

Use: e.ContainedCollection.GetMulti(e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.Relations, e.PrefetchPath, e.PageNumber, e.PageSize);

where 'e' is the event args of the event simple_smile

Frans Bouma | Lead developer LLBLGen Pro
JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 11-Jan-2007 06:38:50   

ok I have insert edit and delete, I don't need NEW command to work as that doesn't fit the use case, working. Now I just want to show the kcurrently entered item. I tried adding the just committed entity to the collection set that should be bound to the form view. I have tried rebinding the controls after adding the entity to the control. I have tried what you stated in last message but that doesn't exist for adapter. I can redirect to a page that has exact same formview on it but that defeats the purpose of code/page reuse. Which was why i downloaded your object.

Bare with me i am learning.

Jeff

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jan-2007 06:51:31   

After you insert an entity into the database, you should re-fetch and re-bind and re-bind (you can use dataSource.Refetch() & formView.DataBind() )

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39896
Joined: 17-Aug-2003
# Posted on: 11-Jan-2007 10:21:09   

To elaborate: after the postback which inserts the item, you effectively will redirect to the same page which then shows your current item. One way to do this is to set the filter of the datasource control to a filter which loads your newly inserted entity. I think that's what Walaa meant. Refetch and databind are automatic so you don't have to call them.

Working with datasourcecontrols (not just ours, all datasourcecontrols have this) isn't easy, and it's inconsistent, IMHO due to the weird nature of how asp.net pages are rendered/processed.

So if you, in the perform work routine set the FilterToUse to a filter which matches the newly inserted item, and then change the mode of the formview to item, it should work.

Mind you: when you have bound a grid to the same datasource control, the entity would be added to the grid and to the collection and would be the active row because the grid forces a filter (either an empty or a set filter) to match the collection.

If you just switch the formview to Item mode after the insert, there's no filter in the datasourcecontrol and thus it will load all entities, and the formview will show the first one.

Frans Bouma | Lead developer LLBLGen Pro
JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 12-Jan-2007 05:20:51   

Ok I have a good idea of what I need to have happen here unfortunately i have tried many things to try and make it happen. Here is what I think should be happening as I have livepersistence=false then I have to manually persist the Entity or collection. Handle the events such as perform work and perform select. I have perform work working. I get a customer record inserted into my db and I have a control on my page a hiddentextbox named CustomerCrid that gets set to the Primary key of the newly created item. I have verified manually that the hidden field is getting a value set to the control and that it does match the primary key of the newly created tuple in the db. I now am trying to display the item.

My page load method works as it should as well. If First load to page set formview to insert otherwise create the predicate to use as the filter.

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'In case I want to use a queryStrings in the future for a different use case 'If no keys then use case is adding a new connectivity request for services. If Not Request.QueryString.HasKeys Then If Not Page.IsPostBack Then 'this is first time access so workflow requires an insert. 'MsgBox("No Keys") customerFV.ChangeMode(FormViewMode.Insert) End If If Page.IsPostBack Then 'Not first access to page so show inserted item should be 'Example SQL command would be get * from customer where CRID = customerCRID.Text Dim bucket As New RelationPredicateBucket bucket.PredicateExpression.Add(CustomerFields.Crid = customerCRID.Text) customerDS_A.FilterToUse = bucket End If End If End Sub

Right now the entitycollection held by the datasourceobject2 has a count of 0.Perfect. I have the following code in my perform select method and I am getting the msgboxes to popup. Of course eventually I wo't need them. Keep in mind I am coding in VB.

Sub CustomerDS_A_PerformSelect(ByVal sender As Object, ByVal e As PerformSelectEventArgs2) Handles customerDS_A.PerformSelect MsgBox(customerDS_A.FilterToUse.PredicateExpression.Count.ToString) MsgBox("Count of Collection " & customerDS_A.EntityCollection.Count.ToString) End Sub

Which yields a message box showing "1" then a message box which shows "Count of Collection 0" Which tells me that I need to clear or reset the Collection and then refetch it and bind it to the formview so it will display. I have looked and looked for a method which would perform the refetch. Otis you stated to do the following. Use: e.ContainedCollection.GetMulti(e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.Relations, e.PrefetchPath, e.PageNumber, e.PageSize); where 'e' is the event args of the event

This doesn't exist?? I get the following error

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30456: 'GetMulti' is not a member of 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2'.

walaa you state to do the following dataSource.Refetch() & formView.DataBind() great so in vb I would state ds.refetch = true which would mark the object to be refetched if LIVEPERSISTENCE=TRUE which it is not. then you state to fv.databind() which gets me into my performselect method.

?????? What am I missing I wish I had the source code for the SD.LLBLGen.Pro.ORMSupportClasses so that I could dig into them and read and look and see what they are doing there. I don't mean to say that I would change them I think everything is fine I just think I am missing something really simple.

Thanks Jeff

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2007 08:20:13   

Compiler Error Message: BC30456: 'GetMulti' is not a member of 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2'

GetMulti() is a method found in IEntityCollection which is used in the SelfServicing.

Using the Adapter model, you should be using the IEntityCollection2 and you should call adapter.FetchEntityCollection(),

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39896
Joined: 17-Aug-2003
# Posted on: 12-Jan-2007 10:26:14   

JeffM: Sorry for the misunderstanding, I though you were using selfservicing. It's unclear to me what exactly you're using, as at one time you're using adapter, then in another post you mention DAO classes, so I thought it was selfservicing.

Frans Bouma | Lead developer LLBLGen Pro
JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 12-Jan-2007 21:54:44   

Sorry for the confusion but I was using selfservicing until halfway through the postings here then I tried both ways and it seems that the adapter works a little faster thanks for the info walla

JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 12-Jan-2007 22:34:28   

If I have a select parameter for the objectdatasourcecontrol2 then when I use the Adapter.FetchEntityCollection(customerDS_A.EntityCollection, ?????) do I have to manually create the filter predicate? It is working but still bringing up all records in db not using the select parameter I have built?

Thanks Jeff

JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 13-Jan-2007 03:10:54   

YEAH thank you for all of your pushes in the right direction. I have the CustomerDS_A adapter as ObjectDataSource2 working just fine on a single page without redirection, with my validation the way I wanted it to be and it is GREAT alot better than the other ways that I had it working with other controls.

Jeff

Thanks

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39896
Joined: 17-Aug-2003
# Posted on: 13-Jan-2007 09:53:05   

Glad you got it working, Jeff smile

Frans Bouma | Lead developer LLBLGen Pro
1  /  2