开发者

Linq To Entity :: What the following code is doing?

I am running this query but i am unsure of what is it fetching ?

var sm = pe.C开发者_如何学编程ategories.Include("ParentCategory").Where(c => c.ParentCategory.CategoryName == "Electronics");

What will the variable sm have ??


Edit - You need to remove the Include statement. Linq-to-Entities will allow you to access the properties of the entity without having to include them

var sm = pe.Categories
           .Where(c => c.ParentCategory.CategoryName == "Electronics"); 
  • sm will be an IQueryable of type Category

  • It will contain Categories where its ParentCategory CategoryName is "Electronics"

  • Each cateogry will have its ParentCategory preloaded for you


var sm = pe.Categories
           .Where(c => c.ParentCategory.CategoryName == "Electronics");

This should work as you expect. Adding Include preloads the specified entity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜