diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..a88e69e --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @DevExpressExampleBot \ No newline at end of file diff --git a/Readme.md b/Readme.md index 5cd2f4f..cc7916a 100644 --- a/Readme.md +++ b/Readme.md @@ -1,35 +1,114 @@ -![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128592807/24.2.1%2B) [![](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) [![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183) [![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives) - -*Files to look at*: -* [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs) -* [Model.DesignedDiffs.xafml](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Model.DesignedDiffs.xafml) -* [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs) -* [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs) - + + # How to search for XAF objects using a complex criterion +This example creates a pop-up window that allows users to perform a custom object search. + +![MySearchClass window](my-search-class-window.png) + +## Implementation Details -To accomplish this task, take the following steps: +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. + _File to review: [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)_ + ```cs + [DomainComponent] + public class MySearchClass : NonPersistentBaseObject { + [XafDisplayName("FirstName contains:")] + public string FirstName { get; set; } + [XafDisplayName("Age is equal to:")] + public int Age { get; set; } + // ... + } + ``` +2. Add a collection of persistent objects that contains the search results. + _File to review: [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs)_ + ```cs + [DomainComponent] + public class MySearchClass : NonPersistentBaseObject { + // ... + private IList _contacts = new List(); + [XafDisplayName("Results:")] + public IList Contacts { + get { + return _contacts; + } + } + } + ``` -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) -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. -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) -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) -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) +3. Add the **MySearch** action that populates the collection. + _File to review: [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)_ + ```cs + public class MySearchController : ObjectViewController { + public MySearchController() { + var myAction1 = new SimpleAction(this, "MySearch", "MySearchCategory"); + myAction1.Execute += MyAction1_Execute; + } + // ... + } + ``` + +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. + _File to review: [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs)_ + ```cs + public class MySearchController : ObjectViewController { + // ... + private void MyAction1_Execute(object sender, SimpleActionExecuteEventArgs e) { + var mySearchObject = (MySearchClass)View.CurrentObject; + var persistentOS = Application.CreateObjectSpace(typeof(Contact)); + var criterion = CriteriaOperator.FromLambda(x => x.FirstName.Contains(mySearchObject.FirstName) || x.Age == mySearchObject.Age); + var results = persistentOS.GetObjects(criterion); + mySearchObject.SetContacts(results); + } + } + ``` + +5. Create the **MyShowSearchAction** to display the **MySearchClass** detail view from the **Contact** list view in a pop-up window. + _File to review: [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs)_ + ```cs + public class MyShowSearchController : ObjectViewController { + public MyShowSearchController() { + var mypopAction1 = new PopupWindowShowAction(this, "MyShowSearchAction", PredefinedCategory.Edit); + mypopAction1.TargetViewNesting = Nesting.Root; + mypopAction1.CustomizePopupWindowParams += MyAction1_CustomizePopupWindowParams; + } + private void MyAction1_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { + var nonPersistentOS = (NonPersistentObjectSpace)Application.CreateObjectSpace(typeof(MySearchClass)); + var persistentOS = Application.CreateObjectSpace(typeof(Contact)); + nonPersistentOS.AdditionalObjectSpaces.Add(persistentOS); + var obj = nonPersistentOS.CreateObject(); + nonPersistentOS.CommitChanges(); + var view = Application.CreateDetailView(nonPersistentOS, obj); + e.View = view; + } + } + ``` + + +## Files to Review +* [MySearchClass.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/BusinessObjects/MySearchClass.cs) +* [Model.DesignedDiffs.xafml](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Model.DesignedDiffs.xafml) +* [MySearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MySearchController.cs) +* [MyShowSearchController.cs](CS/EFCore/ComplexSearchEF/ComplexSearchEF.Module/Controllers/MyShowSearchController.cs) -![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) +## Documentation +- [Non-Persistent classes](https://docs.devexpress.com/eXpressAppFramework/116516/business-model-design-orm/non-persistent-objects) +- [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) +- [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) +- [Create, Read, Update and Delete Data](https://docs.devexpress.com/eXpressAppFramework/113711/data-manipulation-and-business-logic/create-read-update-and-delete-data) +- [Ways to Show a View](https://docs.devexpress.com/eXpressAppFramework/112803/ui-construction/views/ways-to-show-a-view/ways-to-show-a-view) ## Does this example address your development requirements/objectives? -[](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) [](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) +[](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF-search-objects-using-complex-criterion&~~~was_helpful=yes) [](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF-search-objects-using-complex-criterion&~~~was_helpful=no) (you will be redirected to DevExpress.com to submit your response) diff --git a/my-search-class-window.png b/my-search-class-window.png new file mode 100644 index 0000000..8321533 Binary files /dev/null and b/my-search-class-window.png differ