是否可以投影对象的每个属性并添加更多属性,而无需专门列出所有属性。例如,不要这样做:
var projection = from e in context.entities
select new QuestionnaireVersionExtended
{
Id = e.Id,
Version = e.Version,
CreationDate = e.CreationDate,
...
many more properties
...
NumberOfItems = (e.Children.Count())
};
我们可以做这样的事情:
var projection = from e in context.entities
select new QuestionnaireVersionExtended
{
e,
NumberOfItems = (e.Children.Count())
};
它将从 e 中获取具有相同名称的每个属性,并在其中添加“NumberOfItems”属性?