DataMapper?

DataMapper?

Old forum URL: forums.lhotka.net/forums/t/5250.aspx


ajj3085 posted on Friday, August 15, 2008

I'm building my asp.net app, and using the PTrackWeb as a sample.  I notice the use of the DataMapper.  I thought Asp.Net was now supporting two-way databinding... so is this necessary?  Also, My BO holds the database id, and I store the BO in the Session object.. do I still need to worry about the datamapper trying to set that value?

Is this new to 3.5?  I wasn't able to find anything in the books.

RockfordLhotka replied on Friday, August 15, 2008

DataMapper is used in the 2005 book and was introduced in CSLA .NET 2.0. Check the web UI chapter (10?).

It was created specifically to support the two-way data binding in Web Forms, though it is also useful when creating XML services.

If you look at PTWeb, you'll see that the CslaDataSource raises events for insert and update. These are triggered when the user clicks the inert/update links in a DetailsView or similar control.

In that case, Web Forms data binding takes the values from the UI control and puts them into a Dictionary<string, object> and you get the dictionary. You must then copy the values from the dictionary into your object's properties. You can do that by hand - one line of code per property, or you can use DataMapper. Either way works.

Copyright (c) Marimer LLC