用于分层数据的ABP AppService

时间:2018-03-20 06:57:14

标签: hierarchical-data aspnetboilerplate devextreme

我需要一个AppService来加载一个树视图,其中包含这些实体的递归集合:

SELECT ?hometown 
WHERE {
dbr:Arctic_Monkeys dbo:hometown ?label.
?label rdfs:label ?hometown.
FILTER(langMatches(lang(?hometown), "en"))
}

是否有派生的现成课程?如果没有,你能建议推导出什么类或实现什么接口,以及如何继续,

PS:可能有完整的CRUD操作,但最重要的是了解如何加载数据。

2 个答案:

答案 0 :(得分:1)

您可以使用Include方法指定要包含在查询结果中的相关数据。

请参阅Loading Related Data

您可以参考以下示例。

using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace EFQuerying.RelatedData
{
    public class Sample
    {
        public static void Run()
        {
            #region SingleInclude
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                    .ToList();
            }
            #endregion

            #region IgnoredInclude
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                    .Select(blog => new
                    {
                        Id = blog.BlogId,
                        Url = blog.Url
                    })
                    .ToList();
            }
            #endregion

            #region MultipleIncludes
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                    .Include(blog => blog.Owner)
                    .ToList();
            }
            #endregion

            #region SingleThenInclude
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                        .ThenInclude(post => post.Author)
                    .ToList();
            }
            #endregion

            #region MultipleThenIncludes
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                        .ThenInclude(post => post.Author)
                            .ThenInclude(author => author.Photo)
                    .ToList();
            }
            #endregion

            #region MultipleLeafIncludes
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                        .ThenInclude(post => post.Author)
                    .Include(blog => blog.Posts)
                        .ThenInclude(post => post.Tags)
                    .ToList();
            }
            #endregion

            #region IncludeTree
            using (var context = new BloggingContext())
            {
                var blogs = context.Blogs
                    .Include(blog => blog.Posts)
                        .ThenInclude(post => post.Author)
                        .ThenInclude(author => author.Photo)
                    .Include(blog => blog.Owner)
                        .ThenInclude(owner => owner.Photo)
                    .ToList();
            }
            #endregion

            #region Eager
            using (var context = new BloggingContext())
            {
                var blog = context.Blogs
                    .Single(b => b.BlogId == 1);

                context.Entry(blog)
                    .Collection(b => b.Posts)
                    .Load();

                context.Entry(blog)
                    .Reference(b => b.Owner)
                    .Load();
            }
            #endregion

            #region NavQueryAggregate
            using (var context = new BloggingContext())
            {
                var blog = context.Blogs
                    .Single(b => b.BlogId == 1);

                var postCount = context.Entry(blog)
                    .Collection(b => b.Posts)
                    .Query()
                    .Count();
            }
            #endregion

            #region NavQueryFiltered
            using (var context = new BloggingContext())
            {
                var blog = context.Blogs
                    .Single(b => b.BlogId == 1);

                var goodPosts = context.Entry(blog)
                    .Collection(b => b.Posts)
                    .Query()
                    .Where(p => p.Rating > 3)
                    .ToList();
            }
            #endregion
        }
    }
}

答案 1 :(得分:1)

_productRepository     .GetAllIncluding(X => x.Products)     。哪里(p => p.Id == 1); //或任何条件     .ToList()

这将为您提供Id 1的产品和子产品列表。