如何在EF中包含子集? [英] How to include subset in EF?
问题描述
这里是代码:
public IQueryable< T> GetList< T>()其中T:class
{
var result = dbContext.CreateObjectSet< T>();
返回结果;
}
我有一个来自数据库的内容表。它已被转换为内容对象。内容对象具有称为状态的相关子集。我如何使用我的查询来包含它?
这是我目前的功能:
public IQueryable< Content> GetContentList()
{
var contentList = GetList< Content>();
return contentList;
}
但是,不包括状态子集。我的问题是如何包括它?
非常感谢
p>我不熟悉 CreateObjectSet< T>
。您是否有一个 ContentSet
来查询LINQ to Entities?
var result = dbContext.ContentSet.Include(States);
在我的例子中, Include
方法是一个明确地包括你的国家。
I wrote a tiny function which return a generic IQueryable object. Here is the code:
public IQueryable<T> GetList<T>() where T : class
{
var result = dbContext.CreateObjectSet<T>();
return result;
}
I have a content table from the database. It has been converted into a content object. The content object has a related subset called State. How do I include it with my query?
Here is my current function:
public IQueryable<Content> GetContentList()
{
var contentList = GetList<Content>();
return contentList;
}
It works, however, the State subset is not included. My question is how to include it?
Thanks a lot.
I'm not familiar with CreateObjectSet<T>
. Don't you have a ContentSet
to query with LINQ to Entities?
var result = dbContext.ContentSet.Include("States");
In my example the Include
method is the one that explicitly includes your States.
这篇关于如何在EF中包含子集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!