检索DBSET< t>的通用方法来自dbContext和使用Incluph()方法C#
我制作了此功能来检索所有数据。
public static List<Volunteer> GetAllVolunteers()
{
using (VolunteerPlacementSystemDBEntities1 db = new VolunteerPlacementSystemDBEntities1())
{
return db.Volunteers.**Include(v => v.roleForVolunteers).Include(v => v.VolunteerOffers)
.Include("VolunteerOffers.daysForAVolunteers")**.ToList();
}
}
而且我具有检索DBSET T的通用功能。
public static List<T> GetDbSet<T>() where T : class
{
using (VolunteerPlacementSystemDBEntities1 db = new VolunteerPlacementSystemDBEntities1())
{
return db.GetDbSet<T>().ToList();
}
}
我可以制作一个通用函数,以检索连接到一个DBSET T的所有数据吗?
提前致谢。
I made this function that retrieves all the data.
public static List<Volunteer> GetAllVolunteers()
{
using (VolunteerPlacementSystemDBEntities1 db = new VolunteerPlacementSystemDBEntities1())
{
return db.Volunteers.**Include(v => v.roleForVolunteers).Include(v => v.VolunteerOffers)
.Include("VolunteerOffers.daysForAVolunteers")**.ToList();
}
}
And I have this generic function that retrieves DBSet T.
public static List<T> GetDbSet<T>() where T : class
{
using (VolunteerPlacementSystemDBEntities1 db = new VolunteerPlacementSystemDBEntities1())
{
return db.GetDbSet<T>().ToList();
}
}
Can I make a generic function that will retrieve all the data that connect to one DBSet T?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
获取
dbset
t
从上下文中的实体类类型,例如dbset&lt; t&gt;
或iqueryable&lt; t&gt;
。在此
上> etc,在命名空间
system.linq
的帮助下。使用
include()
方法,传递所需的属性。用于并行处理,使用
system.threading.tasks
的TPL
尝试以下操作:
Get
DbSet
for theT
Entity Class Type from context asDbSet<T>
orIQueryable<T>
.On this
IQueryable<T>
object can perform multiple operations likeWhere()
,Include()
,orderBy()
etc with help of namespaceSystem.Linq
.With
Include()
method, pass on required included properties.For Parallel processing use TPL from
System.Threading.Tasks
Try this:
大个月前,我尝试这样做这样的事情,但是我有tablename。我给您一些细节,可以使
您的提取提取曲目上下文,并仅选择t类型的clrtype corrispond。
这是我的自定义课程
的所有参考属性
,您可以提取我希望可以帮助您
。 *** 编辑
如果您需要自定义,则可以使用
iincludableQueryable&lt; t,对象&gt;&gt;
Some month ago i try to do somthing like that, but i have tableName. I leave you some detail, that you can adapt
You extract form context all your table and select only the ClrType corrispond with your T type.
This is my custom class
then you can extract all your reference property
I wish that can help you.
*** EDIT
If you need a custom include of T you can use
IIncludableQueryable<T, object>>
感谢所有试图帮助我的人。
这是对我有用的解决方案。
Thanks to everyone who tried to help me.
This is the solution that worked for me.