injecting from IEnumerable<Type1> to IEnumerable<Type2> where Type1 similar to Type2

Jan 26, 2012 at 10:59 AM

ValueInjecter looks to be exactly what I am looking for, except that I havent seen any examples of mapping from a list to a list "automagically" (ie, little or no code to write).

Heres the scenario, which I think would be very common.  I have a Data Access layer, using EF Code First.  I define my entities in the DAL, with all the attributes that make sense for a CF type model (like MaxLength, NotMapped, etc).  I dont want to dirty the rest of the app with these classes - they are only for persistence.

Out in the Business Logic layer(s) I have domain objects, pretty much one Domain object for each DAL entity.  The two sets of classes are very similar, but not exactly the same.  I want to map back and forth easily.

Quite often my DAL will query the datastore, and get a list of DAL entities that I then want to return to the Business Logic caller as Domain Entities.  

So can I do something like 

IEnumerable<DomainType> dt = new IEnumerable<DomainType>();

IEnumerable<DALType> dal = new IEnumerable<DALType>();


Jan 26, 2012 at 11:36 AM

you could do it in a foreach

or using linq  .Select( o => new Domain().InjectFrom(o))

or you can also look at AutomapperSimulation (available for download), there the collections are mapped automatically

Mar 29, 2012 at 1:05 PM

were you able to implement this scenario?. Can you please reply with an example implementation..

Mar 29, 2012 at 1:10 PM

look at the automapper simulation, you can also download it