我有一个看起来像这样的查询:
var qContactsOpen = from x in promo.Contacts
where x.type == type && (x.closure_id == 0 || x.closure_id == null)
orderby x.id descending
select new ContactsGrid
{
Id = x.id,
DescriptionA = x.description_A,
Address = x.address,
PostalCode = x.postal_code,
Vat = x.vat_iva,
CategoryDescription = x.Categories.description,
SpecializationDescription = x.Specializations.description,
AreaDescription = x.Areas.description,
Location = x.location,
Subject = x.subject,
Note = x.ContactsActivities.OrderByDescending(o=>o.date).FirstOrDefault().note
};
选择中的最后一个字段是一个字符串属性,我需要如果x.ContactsActivities
大于0,则取结果,否则将字符串取空。
如果我运行它,将返回一个错误,它不能按 null 排序。