Ok ich habe folgende, Einrichtung und funktioniert super. Diese Codezeilen sollten eine Konvertierung von DAL Entity (Subsonic) zu einem ViewModel durchführen.Loop zu LINQ Conversion -
IList<ProductOptionModel> OptionsRetData = new List<ProductOptionModel>();
foreach (var CurProductOption in this.ProductOptions)
{
OptionsRetData.Add(CurProductOption.ToDataModel());
}
returnData.Options = OptionsRetData.AsEnumerable();
Ich möchte dies in eine LINQ Single Line Statment konvertieren und kam auf die folgenden.
returnData.Options = this.ProductOptions.Select(o => o.ToDataModel());
und ich empfange den folgenden Fehler.
Server Error in '/' Application.
Sequence contains no matching element
Also warum funktioniert die erste Anweisung, aber nicht die LINQ und, welche Schritte kann ich nehmen, um es zu lösen.
Stack Trace
bei System.Linq.Enumerable.First [TSource] (IEnumerable
1 source, Func
2 Prädikats) bei SubSonic.Extensions.Database.Load [T] (IDataReader RDR, T Einzelteil, Liste1 ColumnNames) at SubSonic.Extensions.Database.ToEnumerable[T](IDataReader rdr, List
1 Column) bei SubSonic.Linq.Structure.DbQueryProvider.Execute [T] (QueryCommand1 query, Object[] paramValues) at lambda_method(Closure) at SubSonic.Linq.Structure.DbQueryProvider.Execute(Expression expression) at SubSonic.Linq.Structure.Query
1.GetEnumerator()
Vielleicht ist das mit subsonic zu tun?
Was ist der Call-Stack der Ausnahme? – SLaks
Was ist der Rückgabetyp von ToDataModel()? –
@Dave Swersky - Rückgabetyp ist ProductOptionModel – LiamB