Let's say I have this view model:
public class SeriesLinkViewModel
{
public static Expression<Func<Series, SeriesLinkViewModel>> FromSeries =
s => new SeriesLinkViewModel
{
Name = s.Name,
Slug = s.Slug,
};
public string Name { get; set; }
public string Slug { get; set; }
}
I attached the projection function there for convenience, so now I can say something like:
var links = dc.Series.Select(SeriesLinkViewModel.FromSeries);
Tall. But what should I do if I want to add to this request? Say I also wanted to pull a column Descriptionfrom a table. Usually I could just do select new { }and put it there Description, but I can't do it because I can only put one projection function in `.Select ().
I was hoping I could do something like this:
q = from s in dc.Series
select new
{
Series = SeriesLinkViewModel.FromSeries.Compile()(s),
Description = s.Description
};
But I get an exception:
System.InvalidCastException: cannot cast object of type 'System.Linq.Expressions.FieldExpression' to print 'System.Linq.Expressions.LambdaExpression'.
? , TransactionScope , , .