开发者

If my Service Returns an IEnumerable of Entities, can I Lazy Load Related Entities?

开发者 https://www.devze.com 2023-03-24 03:38 出处:网络
I have this entity: public class Product { public string Name { get; set; } public double Price { get; set; }

I have this entity:

public class Product
{
    public string Name { get; set; }
    public double Price { get; set; }

 开发者_StackOverflow社区   public ProductManufacturer Manufacturer { get; set; }
}

I want my Services to return a list of Products to display in a View. I also need to display information about the related manufacturer (Product.Manufacturer) using lazy loading.

Should my Services return an IQueryable or an IEnumerable? Thank you.


IEnumerable<T> and IQueryable<T> are both interfaces. Neither of them "support" lazy loading.


I think the items are not serialized before you use them, if that's what you mean. I have had issues with this, returning LINQ expressions from WCF services, and gotten exceptions when the WCF serializer tries to serialize the result. The solution is to call ToArray() on the IQueryable result before serializing it.

Don't know if that completely answers your question?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号