1
你好我想包括儿童和LINQ孩子的对象包括孩子和孩子的对象时,子对象不是列表或集合
这里是我的父类
public class SharePost : BasePost
{
public Address Address { get; set; }
public ICollection<Picture> Pictures { get; set; }
}
这里是我的子类这是“地址”
public class Address
{
public SharePost SharePost { get; set; }
public int PostId { get; set; }
public Place Place { get; set; }
public int PlaceId { get; set; }
public Suburb Suburb { get; set; }
public int SuburbId { get; set; }
}
基本上,SharePost
和Address
是一比一的关系。所以它们具有相同的主键值。然后,当我加载SharePost对象时,我想包括Place
和Suburb
对象。所以我尝试这样
public SharePost GetFullSharePost(int postId)
{
return DataContext.SharePosts.Include(m => m.Address.Select((a => a.Suburb)) && (a => a.Place))
}
但Address.Select()
不起作用。 Asp.net无法识别地址上的Select()
方法。 Select()
仅适用于List或ICollection
?那么我怎样才能包括Place
和Suburb
对象在Address
当我加载Sharepost
对象?