Carlos Mendes - 125 - Mar 15, 2014

I need to get an User from the DB and update it from a Dto using auto-mapping.

Considering the following DTO:

 public class UpdateUserDto
    {
        public string Id { get; set; }
        public string Username { get; set; }
        public DateTimeOffset CreatedOn { get; set; }
        …
        …
        public UserPreferences UserPreferences { get; set; }
    }

When I’m updating the User I need to ignore some properties from the UpdateUserDto since they should not be changed (e.g.: Id, CreatedOn).

I know that I can use the PopulateFromPropertiesWithAttribute but usually I just want to exclude 2 or 3 properties from Dto’s that have 10 to 15 properties.

I was wondering if it wouldn’t be useful to have a “[NonDataMember]” attribute to select properties that should be ignored during the mapping. 

Any other suggestions?

You can always update a partial list of fields using OrmLite’s db.UpdateOnly method. Give the methods on the DTO non-conflicting names. Or copy back the properties you don’t want to overridden manually. 

I’ve also added a PopulateFromPropertiesWithoutAttribute in this commit: https://github.com/ServiceStack/ServiceStack.Text/commit/9bd0cc35c0a4e3ddcb7e6b6b88e760f45496145b so you can map all properties without an attribute.

I don’t want to add any new conflicting/confusing attributes, as there is already IgnoreDataMember for serializers + Ignore for OrmLite.

Carlos Mendes:

Many thanks!
__________