예제 #1
0
        /// <summary>
        /// Projects each product of a sequence into a new form.
        /// </summary>
        public static IQueryable <MailMessageItem> Select(this IQueryable <ProjectMailMessage> query, MailMessageField fields)
        {
            Expression <Func <ProjectMailMessage, MailMessageItem> > selector = mailMessage => new MailMessageItem
            {
                Id           = mailMessage.Id,
                Subject      = mailMessage.Subject,
                ModifiedDate = mailMessage.ModifiedDate
            };

            if (fields.HasFlag(MailMessageField.Project))
            {
                selector = selector.Merge(mailMessage => new MailMessageItem
                {
                    Project = new UniqueItem {
                        Id = mailMessage.Project.Id, Name = mailMessage.Project.Name
                    }
                });
            }

            if (fields.HasFlag(MailMessageField.Body))
            {
                selector = selector.Merge(mailMessage => new MailMessageItem
                {
                    Body = mailMessage.Body
                });
            }

            return(query.Select(selector));
        }