a34546 / Wei.Repository

基于.Net6,EFCore+Dapper 封装Repository,实现UnitOfWork,提供基本的CURD操作,支持多数据库,多DbContext
MIT License
82 stars 25 forks source link

How use include to get other entity? #6

Closed felaray closed 6 months ago

felaray commented 1 year ago

I'm work for this,it's patty good!

But when I trying to use include to query relation entity,I dont how do this.

Can I use some include method like this?

Repository

public IQueryable<TEntity> List(params string[] includes)
{
    var query = _dbEntitySet.AsQueryable();
    foreach (var include in includes)
        query = query.Include(include);
    return query;
}

Service

var data = _unitOfWork.GetEntityList<User>("Todo","Diary");

a34546 commented 1 year ago

Please refer to Microsoft efcore documentation

https://learn.microsoft.com/en-us/ef/core/querying/related-data/eager