asp.net - ExpressMapper tutorial assumptions -- I don’t know where to start -


current project:

  • asp.net 4.5.2
  • mvc 5
  • ef 6

in honesty, have never made use of mapper before, , while expressmapper tutorial bounces across high-altitude highlights, makes several assumptions knowledge don’t have.

so in no general order:

the product supposed have code centralized in 1 spot. spot? put it? examples start out with,

public void mappingregistration() {     mapper.register<product,productviewmodel>(); } 

but don’t know put this. go own file or in file, such within app_start?

if elsewhere in project, create under own namespace?

if have viewmodel filled in different way datamodel filled, how handle each type separately? in, data pulled out of db , fills viewmodel different conditional rules how data pulled viewmodel , inserted or updated database.

how bring in external conditionals affect how data , data inserted db, such role of user, userid , username, , various project settings? depending on conditionals, entries may end null value instead of actual value. how can business logic validation using these conditionals (user updating own record, comparing session userid userid stored in db)?

right doing lot of manual mapping in models problematic since method using (to cut down on code in controller) means during update cannot examine entry in db prior updating in db.

you can stick anywhere want - thing necessary gets called in code, before call mapper.map<product,productviewmodel>.

e.g.

public static void main() {     mapper.register<product,productviewmodel>(); } 

is functionally same as

public static void main() {     registermapping(); }  public static void registermapping() {     mapper.register<product,productviewmodel>(); } 

if want map 1 class member class member different name, can specify member mapping.

mapper.register<product, productviewmodel>()     .member(dest => dest.efgh, src => src.abcd); 

if want apply special conversion rules, can specify function mapping - e.g. want price in productviewmodel 2x price of product :

mapper.register<product, productviewmodel>()     .function(dest => dest.price, src => src.price*2); 

any customisation make mapping should done @ time register mapping, , has done on member-by-member basis afaik.

if there's else specific need with, leave comment.


Comments