简体   繁体   English

EF Core 如何过滤 treeview 而不实际将数据保存到数据库中

[英]EF Core how to filter treeview without actually saving data in to the database

I have to filter a telerik radtreeview structure of EF Core objects like below, I need all Employees with the name "John", filtering is working fine,我必须过滤 EF Core 对象的 telerik radtreeview 结构,如下所示,我需要名为“John”的所有员工,过滤工作正常,

-> Companies (Company A, Company B) -> 公司(A 公司、B 公司)

--> Departments (In Company A => IT, HR, Admin) --> 部门(在 A 公司 => IT、HR、管理员)

---> Employees (In IT => John, Smith, Aron) ---> 员工(在 IT => John、Smith、Aron)

So After filter, if I do some action which Save context changes, it causes app to save filtered data as well.因此,过滤后,如果我执行一些保存上下文更改的操作,它也会导致应用程序保存过滤后的数据。 Eg From above example relationship between IT and Smith, Aron breaks.例如,从上面的 IT 和 Smith 之间的关系示例中,Aron 中断了。

Any suggestions on how to implement this without actually getting this data saved in DB and also without using any other model classes.关于如何在不实际将这些数据保存在 DB 中以及不使用任何其他 model 类的情况下实现这一点的任何建议。

Following is a sample code以下是示例代码

private ObservableCollection<Company> FilterCollection(ObservableCollection<Company> collection)
    {
        foreach (Company company in collection)
        {
            foreach (Departments department in company.Departments)
            {
                department.Employees = new List<Employees>(department.Employees.Where(p => p.name == "John"));
            }
        }
        return new ObservableCollection<Company>(collection);
    }

You can create in the method a list of items of the type Company.您可以在该方法中创建公司类型的项目列表。 You can iterate the collection received as a parameter, and every item that matches your rules (Have the name John for example), add it to the list created.您可以迭代作为参数接收的集合,并将每个符合您的规则的项目(例如,名称为 John),将其添加到创建的列表中。 And at the end, return the generated list.最后,返回生成的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM