ASP.NET 2.0 DataBinding (ObjectDataSource)

Posts   
 
    
Posts: 24
Joined: 11-Feb-2004
# Posted on: 26-Apr-2005 18:06:43   

I have been playing around with Beta 2, ObjectDataSource and LLBLGen for the last couple of days. The self-servicing templates work <i>almost</i> perfectly with ASP.NET 2.0 databinding.

It was easy to wrap each entity class in a Table Module pattern, adding the methods required for databinding (e.g. GetCustomers, InsertCustomer, UpdateCustomer, DeleteCustomer). By default, the ObjectDataSource passes the bound object to each method so code such as this would work:


public bool UpdateCustomer(CustomerEntity customer)
{
     return customer.Save(false);
}

Unfortunately, there is one issue. Apparently, the ObjectDataSource builds a new entity class to pass in to the UpdateCustomer method and binds each field in the databound control to its associated property. This doesn't work if your entity has any readonly fields, which is almost always rage .

The workaround is to create methods that accept the actual values of the parameters instead of the object as a whole:


public void UpdateRecord(int topicId, string topicName, int original_TopicId)
{
     TopicsEntity topic = new TopicsEntity(original_TopicId);
     topic.TopicName = topicName;               
     topic.Save(false);
}

Besides being more work, this requires modification to the table module if new elements are added to the UI.

I'm not sure if anything can be done about this. Ideally for me, the ObjectDataSource would keep the original objects around and return them with their udpated properties. Of course, this breaks the stateless design and is probably a Bad Thing.

If anyone else has run into this issue and come up with a brilliant workaround, let me know simple_smile . Likewise, if I come up with something clever I will post it here.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Apr-2005 22:15:04   

I've to look more into the details on this, as before beta2 there was very little known (and only in the standard Microsoft way: Datasets DATA SETS!!! Did I ALREADY mention DATASETS???).

What I did figure out was some sort of .xsd based design time experience. I'm not sure if this is true, but if so, generating .xsd's would be enough... but I doubt it though...

(is the table thing the only way to deal with this btw?)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 8
Joined: 23-Apr-2005
# Posted on: 27-May-2005 06:51:13   

I ran into this issue tonight with beta 2. I've been banging my head against the wall for 2-3 hours trying to get this to work; alas, I keep getting the following error when I try to pass in a standard Entity object to me Update method:

'ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'UpdateSingleCustomer' that takes parameters of type '<fully qualified entity type>'. '

So, has anyone come up with a better method than enumerating ALL the fields in the object that need to be updated on the Update method signature?

Chris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 27-May-2005 09:59:30   

I've spend not that enough time with beta2 yet to be able to answer your question, I'm afraid...

Frans Bouma | Lead developer LLBLGen Pro
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 01-Jun-2005 17:34:46   

MVandergrift -

Would you please elaborate on your comment: "wrap each entity class in a Table Module pattern". Perhaps you could provide a short code example.

Thanks.

Jeff