Skip to content

Commit fd9ff68

Browse files
authored
Upd readme 24 2 (#3)
1 parent d905cd2 commit fd9ff68

File tree

2 files changed

+95
-16
lines changed

2 files changed

+95
-16
lines changed

Readme.md

+95-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,114 @@
11
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128592807/24.2.1%2B)
32
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E1744)
43
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
54
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
65
<!-- default badges end -->
7-
<!-- default file list -->
8-
*Files to look at*:
9-
* [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)
10-
* [Model.DesignedDiffs.xafml](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Model.DesignedDiffs.xafml)
11-
* [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)
12-
* [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs)
13-
<!-- default file list end -->
6+
7+
148
# How to search for XAF objects using a complex criterion
159

10+
This example creates a pop-up window that allows users to perform a custom object search.
11+
12+
![MySearchClass window](my-search-class-window.png)
13+
14+
## Implementation Details
1615

17-
To accomplish this task, take the following steps:
16+
1. Create a [non-persistent](https://docs.devexpress.com/eXpressAppFramework/116516/business-model-design-orm/non-persistent-objects) class with properties used to search persistent objects.
17+
_File to review: [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)_
18+
```cs
19+
[DomainComponent]
20+
public class MySearchClass : NonPersistentBaseObject {
21+
[XafDisplayName("FirstName contains:")]
22+
public string FirstName { get; set; }
23+
[XafDisplayName("Age is equal to:")]
24+
public int Age { get; set; }
25+
// ...
26+
}
27+
```
1828

29+
2. Add a collection of persistent objects that contains the search results.
30+
_File to review: [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)_
31+
```cs
32+
[DomainComponent]
33+
public class MySearchClass : NonPersistentBaseObject {
34+
// ...
35+
private IList<Contact> _contacts = new List<Contact>();
36+
[XafDisplayName("Results:")]
37+
public IList<Contact> Contacts {
38+
get {
39+
return _contacts;
40+
}
41+
}
42+
}
43+
```
1944

20-
1. Create a [non-persistent](https://docs.devexpress.com/eXpressAppFramework/116516/business-model-design-orm/non-persistent-objects) class with properties that we will use to find persistent objects: [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)
21-
2. In this class add a collection of persistent objects as described at [How to: Show Persistent Objects in a Non-Persistent Object's View](https://docs.devexpress.com/eXpressAppFramework/116106/business-model-design-orm/non-persistent-objects/how-to-show-persistent-objects-in-a-non-persistent-objects-view#persistent-collection). This collection will show the search results.
22-
3. In this class' non-persistent detail view, add a custom 'Search' action as described at [How to: Include an Action to a Detail View Layout](https://docs.devexpress.com/eXpressAppFramework/112816/task-based-help/miscellaneous-ui-customizations/how-to-include-an-action-to-a-detail-view-layout)
23-
4. When a user presses this 'Search' action, create a criterion based on the properties from point 1 and get persistent objects that fit this criterion as described at the 'Get a collection' section of [Create, Read, Update and Delete Data](https://docs.devexpress.com/eXpressAppFramework/113711/concepts/data-manipulation-and-business-logic/create-read-update-and-delete-data): [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)
24-
5. To show this non-persistent class view, use the solution from [Ways to Show a View](https://docs.devexpress.com/eXpressAppFramework/112803/ui-construction/views/ways-to-show-a-view/ways-to-show-a-view): [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs)
45+
3. Add the **MySearch** action that populates the collection.
46+
_File to review: [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)_
47+
```cs
48+
public class MySearchController : ObjectViewController<DetailView, MySearchClass> {
49+
public MySearchController() {
50+
var myAction1 = new SimpleAction(this, "MySearch", "MySearchCategory");
51+
myAction1.Execute += MyAction1_Execute;
52+
}
53+
// ...
54+
}
55+
```
56+
57+
4. When a user clicks the **MySearch** action, create a criterion based on the properties described in the first step and get persistent objects that fit this criterion.
58+
_File to review: [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)_
59+
```cs
60+
public class MySearchController : ObjectViewController<DetailView, MySearchClass> {
61+
// ...
62+
private void MyAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
63+
var mySearchObject = (MySearchClass)View.CurrentObject;
64+
var persistentOS = Application.CreateObjectSpace(typeof(Contact));
65+
var criterion = CriteriaOperator.FromLambda<Contact>(x => x.FirstName.Contains(mySearchObject.FirstName) || x.Age == mySearchObject.Age);
66+
var results = persistentOS.GetObjects<Contact>(criterion);
67+
mySearchObject.SetContacts(results);
68+
}
69+
}
70+
```
71+
72+
5. Create the **MyShowSearchAction** to display the **MySearchClass** detail view from the **Contact** list view in a pop-up window.
73+
_File to review: [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs)_
74+
```cs
75+
public class MyShowSearchController : ObjectViewController<ListView, Contact> {
76+
public MyShowSearchController() {
77+
var mypopAction1 = new PopupWindowShowAction(this, "MyShowSearchAction", PredefinedCategory.Edit);
78+
mypopAction1.TargetViewNesting = Nesting.Root;
79+
mypopAction1.CustomizePopupWindowParams += MyAction1_CustomizePopupWindowParams;
80+
}
81+
private void MyAction1_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
82+
var nonPersistentOS = (NonPersistentObjectSpace)Application.CreateObjectSpace(typeof(MySearchClass));
83+
var persistentOS = Application.CreateObjectSpace(typeof(Contact));
84+
nonPersistentOS.AdditionalObjectSpaces.Add(persistentOS);
85+
var obj = nonPersistentOS.CreateObject<MySearchClass>();
86+
nonPersistentOS.CommitChanges();
87+
var view = Application.CreateDetailView(nonPersistentOS, obj);
88+
e.View = view;
89+
}
90+
}
91+
```
92+
93+
94+
## Files to Review
95+
* [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)
96+
* [Model.DesignedDiffs.xafml](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Model.DesignedDiffs.xafml)
97+
* [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)
98+
* [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs)
2599

26-
![image](https://github.com/DevExpress-Examples/XAF_how-to-search-for-objects-by-using-all-the-properties-or-by-using-more-complex-criteria-e1744/assets/14300209/c5b8ac4b-9e88-4f29-99cd-b2a0bdf64890)
100+
## Documentation
27101

102+
- [Non-Persistent classes](https://docs.devexpress.com/eXpressAppFramework/116516/business-model-design-orm/non-persistent-objects)
103+
- [How to: Show Persistent Objects in a Non-Persistent Object's View](https://docs.devexpress.com/eXpressAppFramework/116106/business-model-design-orm/non-persistent-objects/how-to-show-persistent-objects-in-a-non-persistent-objects-view#persistent-collection)
104+
- [How to: Include an Action to a Detail View Layout](https://docs.devexpress.com/eXpressAppFramework/112816/task-based-help/miscellaneous-ui-customizations/how-to-include-an-action-to-a-detail-view-layout)
105+
- [Create, Read, Update and Delete Data](https://docs.devexpress.com/eXpressAppFramework/113711/data-manipulation-and-business-logic/create-read-update-and-delete-data)
106+
- [Ways to Show a View](https://docs.devexpress.com/eXpressAppFramework/112803/ui-construction/views/ways-to-show-a-view/ways-to-show-a-view)
28107
29108
<!-- feedback -->
30109
## Does this example address your development requirements/objectives?
31110

32-
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF_how-to-search-for-objects-by-using-all-the-properties-or-by-using-more-complex-criteria-e1744&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF_how-to-search-for-objects-by-using-all-the-properties-or-by-using-more-complex-criteria-e1744&~~~was_helpful=no)
111+
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF-search-objects-using-complex-criterion&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF-search-objects-using-complex-criterion&~~~was_helpful=no)
33112
34113
(you will be redirected to DevExpress.com to submit your response)
35114
<!-- feedback end -->

my-search-class-window.png

44.7 KB
Loading

0 commit comments

Comments
 (0)