Wenn Sie Executing Linq to Entity
können Sie nicht mit dem ClassType
con new
en el select
Abschluss der Abfrage only anonymous types are allowed (new without type)
Sehen Sie sich diesen Ausschnitt aus meinem Projekt an
//...
var dbQuery = context.Set<Letter>()
.Include(letter => letter.LetterStatus)
.Select(l => new {Title =l.Title,ID = l.ID, LastModificationDate = l.LastModificationDate, DateCreated = l.DateCreated,LetterStatus = new {ID = l.LetterStatusID.Value,NameInArabic = l.LetterStatus.NameInArabic,NameInEnglish = l.LetterStatus.NameInEnglish} })
^^ without type__________________________________________________________________________________________________________^^ without type
von Ihnen die new keyword
in Select closure auch auf der complex properties
erhalten Sie diese Fehlermeldung
also remove
die ClassTypes from new
Stichwort zu Linq to Entity
Abfragen ,,
weil es in eine Sql-Anweisung umgewandelt und auf dem SqlServer ausgeführt wird
also wann kann ich die new with types
en select
Abschluss?
Sie können es verwenden, wenn Sie mit folgenden Themen zu tun haben LINQ to Object (in memory collection)
//opecations in tempList , LINQ to Entities; so we can not use class types in select only anonymous types are allowed
var tempList = dbQuery.Skip(10).Take(10).ToList();// this is list of <anonymous type> so we have to convert it so list of <letter>
//opecations in list , LINQ to Object; so we can use class types in select
list = tempList.Select(l => new Letter{ Title = l.Title, ID = l.ID, LastModificationDate = l.LastModificationDate, DateCreated = l.DateCreated, LetterStatus = new LetterStatus{ ID = l.LetterStatus.ID, NameInArabic = l.LetterStatus.NameInArabic, NameInEnglish = l.LetterStatus.NameInEnglish } }).ToList();
^^^^^^ with type
nachdem ich ausgeführt habe ToList
auf Anfrage wurde es in memory collection
Wir können also verwenden new ClassTypes
in ausgewählten