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
.
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
. Likewise, if I come up with something clever I will post it here.