开发者

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

开发者 https://www.devze.com 2023-04-11 04:17 出处:网络
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\");

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

精彩评论

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

关注公众号