Filter Lookup Editor Data Source 筛选器查找编辑器数据源

In this lesson, you will learn how to filter the data displayed by a lookup editor. This editor is shown in the Detail Views for reference properties. It contains a list of objects of another related class. In this lesson, the Contact.Position lookup editor will be filtered. For this purpose, a Many-to-Many relationship will be set between the Position class and the Department class. Then, the objects of the Position class in the Detail View of the Contact object will be filtered, displaying only those Positions that are related to a corresponding Department.

在本课中,您将学习如何筛选查找编辑器显示的数据。此编辑器显示在参考属性的"详细信息视图"中。它包含另一个相关类的对象列表。在本课中,将筛选联系人.位置查找编辑器。为此,将在职位类和部门类之间设置多对多关系。然后,将筛选"联系人"对象"详细信息视图中的"位置"类的对象,仅显示与相应部门相关的位置。

 

Note 注意
Before proceeding, take a moment to review the following lessons:
在继续之前,请花点时间复习以下课程:
  • Inherit from the Business Class Library Class (XPO/EF)
  • Implement Custom Business Classes and Reference Properties (XPO/EF)
  • Implement Dependent Reference Properties (XPO/EF)
  • Set a Many-to-Many Relationship (XPO/EF)
  • Place an Action in a Different Location
  • Set a Many-to-Many relationship between the Position and Department classes. For details, refer to the Set a Many-to-Many Relationship (XPO/EF) lesson.

  • 从商务舱库类 (XPO/EF) 继承

  • 实现自定义业务类和参考属性 (XPO/EF)

  • 实现从属参考属性 (XPO/EF)

  • 设置多对多关系 (XPO/EF)

  • 将操作放置在其他位置

  • 在职位和部门类之间设置多对多关系。有关详细信息,请参阅设置多对多关系 (XPO/EF) 课程。


    eXpress Persistent Objects

          eXpress 持久对象

 

 

复制代码
[DefaultClassOptions]
[System.ComponentModel.DefaultProperty(nameof(Title))]
 public class Department : BaseObject {
   //...
   [Association("Departments-Positions")]
   public XPCollection<Position> Positions {
      get { return GetCollection<Position>(nameof(Positions)); }
   }
}

[DefaultClassOptions]
[System.ComponentModel.DefaultProperty(nameof(Title))]
public class Position : BaseObject {
      //...
   [Association("Departments-Positions")]
   public XPCollection<Department> Departments {
      get { return GetCollection<Department>(nameof(Departments)); }
   }
}
复制代码

 

Entity Framework

实体框架

复制代码
public class Position {
    public Position() {
        //...
        Departments = new List<Department>(); 
    }
    //...
    public virtual IList<Department> Departments { get; set; }
}

    C#
    VB.NET

public class Department {
    public Department() {
        //...
        Positions = new List<Position>();
    }
    //...
    public virtual IList<Position> Positions { get; set; }
}
复制代码

 

  • Invoke the Model Editor for the MySolution.Module project. Navigate to the BOModel | MySolution.Module.BusinessObjects node. Expand the Contact child node and select the Position child node. The properties to the right define the Contact.Position property. Set the DataSourceProperty property to "Department.Positions". As a result, the Position lookup editor will display the Department.Positions collection.
  • Set the DataSourcePropertyIsNullMode property to "SelectAll", to display all existing objects in the Contact.Position editor when the Department.Positions property is not specified.

  • 调用 MySolution.模块项目的模型编辑器。导航到 BOModel |MySolution.模块.业务对象节点。展开"联系人子节点"并选择"位置子节点"。右侧的属性定义"联系人.位置"属性。将 DataSource 属性属性设置为"部门.位置"。因此,"位置查找"编辑器将显示"部门.位置"集合。

  • 将 DataSourcePropertyIsNullMode 属性设置为"选择全部",以在未指定"部门位置"属性时在"联系人.位置"编辑器中显示所有现有对象。

    Tutorial_UIC_Lesson7_1

    Note 注意
    You can perform the task defined above in code. See the Implement Dependent Reference Properties (XPO) topic.
    您可以执行上面在代码中定义的任务。请参阅实现相关引用属性 (XPO) 主题。

     

  • The data source for the Position property is changed each time the Department property is changed. So, the Position property value should be set to "null" ("Nothing" in VB) after its data source has changed. To set a new value from the recreated data source, replace the Department property declaration with the following code.

 

每次更改"部门"属性时,都会更改"位置"属性的数据源。因此,在 VB 中的数据源发生更改后,位置属性值应设置为"空"("无"。要从重新创建的数据源设置新值,请将"部门"属性声明替换为以下代码。

eXpress Persistent Objects

eXpress 持久对象

 

复制代码
[Association("Department-Contacts", typeof(Department)), ImmediatePostData]
public Department Department {
   get {return department;}
   set {
      SetPropertyValue(nameof(Department), ref department, value);
      if(!IsLoading) {
         Position = null;
         if(Manager != null && Manager.Department != value) {
            Manager = null;
         }
      }
   }
}
复制代码

 

 

Note 注意
The similar functionality can not be implemented for the Entity Framework because the current version of EF does not allow to check where are the assignment signal comes from.
无法为实体框架实现类似的功能,因为当前版本的 EF 不允许检查分配信号的来源。

 

  • Run the WinForms or ASP.NET application. Specify the Positions property for Department objects. Invoke a Contact Detail View. The dropdown list for the Position lookup editor contains the Positions assigned to the Department object that is specified by the Department editor:

  • 运行 WinForms 或ASP.NET应用程序。指定"部门"对象的"位置"属性。调用联系人详细信息视图。职位查找编辑器的下拉列表包含分配给部门对象的位置,由部门编辑器指定:

    Tutorial_UIC_Lesson7_2

    Tutorial_UIC_Lesson7_2_0

You can see the changes made in this lesson in the Main Demo | MainDemo.Module project. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

您可以在主演示中看到本课中所做的更改 |主演示模块项目。主演示应用程序安装在%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

.

posted @   code first life  阅读(332)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示