hgs yükleme
My Cart (0)  |  My Orders  |  My Downloads  |  My Auction  |  My Account  |  Help


Login |Register        Search

Data Access in dnn 7.0 - Controlling data Mappings

                Print      Add To Favorite     Add To Watch List     Contact Author

Creator: host   12/3/2012 9:23:10 PM    Author: Charles Nurse   Source: http://www.dotnetnuke.com/Resources/Blogs/EntryId/3534/DAL-2-Controlling-your-Mappings.aspx   Views: 2271    0    0  
Tags:
dnn 7 Data Access Dnn development Module develop petapoco

I presented a session on the DAL 2 at DNN World in Orlando, and a few people asked about “calculated” properties - or properties that do not have any matching column in the database.  This is an important feature for any “auto-mapped” repository implementation, so we have added three new Attributes that control the mapping of properties and columns.

IgnoreColumn Attribute

The first of the new attributes is the IgnoreColumn attribute.  Applying this attribute to a property will mean that the property is ignored when mapping the class to it’s corresponding Database table.  Continuing to use the Task class from previous blog posts, lets look at an updated version where there is a new property that shouldn’t be saved to the Database.

Listing 1: The Task class

image

The new “PropertyNotInDatabase” property does not have a corresponding column in the database, and this would throw an error.  This can be made to work by adding the new IgnoreColumn attribute - see Listing 2.

Listing 2: Aplying the IgnoreColumn Attribute

image

DeclareColumns and IncludeColumn Attribute

An alternative approach is to work the other way - i.e. require the class to specify columns that map to fields in the database.  This would be the preferred approach if the class has less “included” columns than “excluded” columns.  Or maybe as a developer you feel that your intentions are clearer by explicitly including columns to be mapped.

The DeclareColumns attribute can be applied at the class level, and if applied only properties that have the IncludeColumn attribute applied will be mapped to the database table - see Listing 3

Listing 3: Applying the DeclareColumns and IncludeColumns Attributes

image

So this concludes this introductory series of articles on the new DAL 2.  Please continue to send your feedback as you use it in your module development, so we can continue to improve it.


Rating People: 10   Average Rating:     

     DnnModule.com is built to provide DNN quality modules and DNN skins, some of them are free, some not. We wish these stuffs (free or not ) can be useful to you.

     Besides that, we also provide a full range of professional services, ranging from web site build, seo, system management, administration, support, senior consultancy and security services. We act as if your development project or network was ours, with care and respect. We are not satisfied until it works the way you want it to, and we don't silently ignore found issues as somebody else's problem.