在我的模型中,我将Address作为基类,并将MailingAddressEmailPhone作为Address的子类。 Person具有地址,因此查询以获取具有Oakland Mailing地址的人将如下所示:

var peopleInOakland = from p in entities.DbObjectSet.OfType<Person>()
                             from a in p.Addresses.OfType<MailingAddress>()
                             where a.City == "Oakland"
                             select p;


如何在查询结果中也包含此人的邮寄地址?我知道我应该使用Include,但是我不确定如何在MailingAddress参数中命名.Include

提前致谢

最佳答案

您将必须创建一个具有您要查找的特定类型的新类型,如下所示:

var peopleInOakland =
    from p in entities.DbObjectSet.OfType<Person>()
    from a in p.Addresses.OfType<MailingAddress>()
    where a.City == "Oakland"
    select
        new { Person = p, Addresses = p.Addresses.OfType<MailingAddress>() };

10-06 06:38