1

How do I use ValueInjecter with a LINQ join that joins multiple result sets? For example, this code inject result values into CombinedResult object, but I also want some of errorsAndWarning values into CombinedResult. The properties have the same name:

var combined = from result in results.DeferredItems
               join errorsAndWarning in errorsAndWarnings.DeferredItems
                on result.MeetingID equals errorsAndWarning.MeetingID
               select new CombinedResult().InjectFrom(result) as CombinedResult;

Thanks.

Saxman
  • 5,009
  • 11
  • 51
  • 72

1 Answers1

3

Use this:

var combined = from result in results.DeferredItems
               join errorsAndWarning in errorsAndWarnings.DeferredItems
                on result.MeetingID equals errorsAndWarning.MeetingID
               select new CombinedResult().InjectFrom(result)
                                          .InjectFrom(errorsAndWarning)
                                          as CombinedResult;
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • hey , daniel , why does this not works with IQueryable data source ? is there a way to inner join two tables and mapping to a viewmodel ? thx – dfang Aug 16 '12 at 14:31
  • @dfang: "Doesn't work" isn't an error description. What is the problem with your code? – Daniel Hilgarth Aug 16 '12 at 15:31
  • "LINQ to Entities does not recognize the method 'System.Object InjectFrom(System.Object, System.Object[])' method, and this method cannot be translated into a store expression." see my question here : http://stackoverflow.com/questions/11988573 , thx ! – dfang Aug 16 '12 at 15:55