Search This Blog

Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Tuesday, April 3, 2018

Old entries in the XPObjectType table - YOUR FEEDBACK IS NEEDED!


I am reviewing the priority of a quite dated SC item on the subject and wanted to ask the community for help. The problem may occur when old business class libraries exist in the application folder. By default, XPO tries to load them by the XPObjectType info along with the new versions. This may lead to a conflict at runtime or startup performance degradation. In the latter case, assembly type resolution may come at a cost (see the point 3.5 under How to measure and improve the application's performance).

Why are we hesitating to remove old XPObjectType entries by default?
1. Removing old XPObjectType records affects other apps accessing this database and is serious. Outdated service table records may relate to business class records too (inheritance mapping is in use very often). So, deleting them will lead to foreign key constraint violation. Creating a sophisticated generic solution for this is not easy task.

Monday, March 26, 2018

Integrating UnitOfWork and XPObjectSpace descendants into an XAF app


We've made some code changes for v17.2.6+ as well as created two articles for advanced XAF developers who may need the subject for some low-level tuning:





Sub-classing is itself easy.  The most interesting part comes for the two popular security configurations: the Integrated  mode and the Middle-Tier Application Server. Thankfully, this is rarely required for complex or specific scenarios only.  Here are several customer tickets for your reference:

    How to map a property to a calculated database column (implement a read-only persistent property)
    xpo and sql server identity fields
    Using inherited UnitOfWork object
    XAF: Create CreateCustomObjectSpaceProvider with parameters from login window
    SecurityStrategyComplex: How to modify objects/properties in code when the user does not have the permission?

To learn more about low-level options to control how your application saves data and where, check out the How to customize the underlying database provider options and data access behavior in XAF.

Your feedback is needed!
Finally, I am just curious: if you search your entire solution in Visual Studio (Control+Shift+F) for any of the ": UnitOfWork", ": XPObjectSpace", ": XPObjectSpaceProvider" strings or their VB.NET equivalents (e.g., Inherits UnitOfWork), how many occurrences  would you have and for what? Please let me know in the comments!

FreeImages.com/Terry Eaton

Monday, November 27, 2017

Welcome the DataStoreCreated event in the ConnectionDataStoreProvider and ConnectionStringDataStoreProvider classes

This is rather a minor improvement, but I bet it will save code lines for some advanced XAFers who touch the internals of the XPO data layer created by XAF for various low-level database-specific customization like setting connection timeouts, changing default schemas, enabling and customizing caching, service end-points, etc. Check out this updated article for some example code showing the new approach in action.
The DataStoreCreated  event is available in XAF v17.2+. Its event arguments (DataStoreCreatedEventArgs) expose the DataStore and Destination parameters that provide access to the current data store and its type (SchemaChecking,  Updating or Working).

Frankly speaking, this is quite low-level and rarely needed stuff, so we have not yet have it covered in the online docs, only in KBs. So, please refer to my 
How to customize the underlying database provider options and data access behavior in XAF article to learn more about it. Should you have any questions or additional usability suggestions, please let me know.

FreeImages/Chett Cole

Wednesday, November 15, 2017

Database maintenance recommendations for applications created or used with XPO or XAF

We have published a KB article that may help you protect the end application's data and keep the system reliable, fast and running smoothly as time goes on, application data grows and other factors are involved during the application's use in production:

https://www.devexpress.com/kb=T572322


FreeImages.com/Sebastian Danon


I hope you find this information helpful.

See Also:
How to measure and improve the application's performance

Friday, May 19, 2017

Questions on managing the Application Model settings in the database - YOUR FEEDBACK IS NEEDED!

We are reviewing usability of the mechanism responsible for storing and managing Application Model differences in the database (aka ModelDifferenceDbStore), and hence wanted to ask you to tell us about your practical experience with it.

In order to do this, please consider these questions:
1. Differences for which levels are you currently storing in the database and how well does this work for you (shared, user, or both)?

2. Have you required customizing differences stored in the database for already deployed production apps? If so, clarify the following points:
2.1. Was this customization done for shared or user levels?

2.2. List the exact use-case scenarios that needed such customizations (e.g., a client screwed up a View layout and could not reset it back to normal)?
2.3. Which solutions and how often did you use for this customization (e.g., direct database updates, editing raw XML after enabling the Administrative UI inside the app, etc.)?
2.4. How well did your current solutions for different customizations work for you so far and what could be improved in them and why?


3. Have you considered the opportunity to customize shared or user differences using the Standalone Model Editor, which visualizes the actual differences in XML content as a nodes tree? If so, clarify the following points to help us better understand the behavior you expect from such a feature:
3.1. Do you need to customize differences for shared, user or both levels?
3.2. Taking the severeness and effect of this operation over all application users, do you think that a logon form should be shown before someone can perform this customization for security reasons? Or, how do you plan to prevent a power user from obtaining the Standalone Model Editor tool binaries and running it locally for this or even harmful purposes?


We would greatly appreciate your answering these questions or providing any other information that would help us see how the current feature works for you and what can be improved further. 

Please provide answers here in comments or rather in the Support Center to track them easier: https://www.devexpress.com/support/center/question/create
Thanks in advance.


FreeImages.com/Ronit Geller

Tuesday, March 14, 2017

XAF app performance: Reducing the number of simultaneous database connections



Multiple simultaneously opened connections consume your database server memory and thus, have negative impact on your application performance. To diagnose this situation, you can use the following SQL script:

SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame

Thankfully, there is a couple of tricks to optimize your existing apps in production (they are already applied out of the box in new projects).


Thursday, July 14, 2016

Can I connect an XAF application to a custom data source (Web service, OData service, NoSQL database, etc.)?

My colleague Michael and I have recently worked on the article clarifying the currently supported data stores for XAF, because from time to time we receive questions like the one above. Even though this is a very basic information, it is still worth checking out even if you already have some XAF experience. Please let me know if there are any questions on this.


XAF is a framework designed to visualize and work with data represented as business or domain objects. The object-relational mapping (ORM) concept is very important here as in our framework you should not normally think of database tables, stored procedures (SP), SQL statements, but rather operate data in an object-oriented manner. Check out the Business Classes vs Database Tables article and information about Domain Driven Design (DDD) to get more inspirations. To access and manipulate objects, queries for all CRUD operations are performed dynamically based on view properties via the IObjectSpace API in a unified way. This design implies certain requirements to the XAF application data source, and makes it difficult to use an arbitrary data service or a specialized database in this role.

Currently, XAF supports the XPO  and Entity Framework ORM libraries out of the box with the help of the XPObjectSpace/XPObjectSpaceProvider  and EFObjectSpace/EFObjectSpaceProvider APIs respectively. They allow connecting an XAF application directly to relational databases supported by these libraries. See the Database Engines Supported by XPO and Entity Framework Data Providers articles for more details.

Also, starting with version 16.1, we introduced the XAF Mobile (CTP) Application Platform. It exposes the XAF application database via the standard OData V3 service that can be consumed by the XAF mobile client, as well as by any custom client you may want to create. Refer to the FAQ: New XAF HTML5/JavaScript mobile UI (CTP) article for more details.


If data from any custom data source (even NoSQL) needs to be used in some XAF views (not all, because otherwise ROI from using XAF can be low), without replacing the main XAF application data store, non-persistent or POCO objects can be used to represent this data with the help of theNonPersistentObjectSpace/NonPersistentObjectSpaceProvider  APIs.  Non-persistent data is usually not queried from a database using your ORM data model, and this can be extremely helpful for analysis and reporting data obtained from dynamic runtime calculations, stored procedures, arbitrary SQL queries or third-party services. Also, such a non-persistent POCO class may be required if you want to display a standard XAF List or Detail View with temporary data generated in code or loaded from a custom storage; or display an empty View (dialog) and then process the user input. Refer to examples in the "Business Model Design - Non-Persistent Objects" part of the Task-Based Help topic for more details. Alternatively, you can display and manipulate any custom data with the help of non-XAF forms or fully custom user controls embedded into standard XAF views as described at eXpressApp Framework > Concepts > UI Construction > Using a Custom Control that is not Integrated by Default.

Friday, October 9, 2015

Improving performance when a large portion of data matches a workflow activity criterion

Here is a real customer scenario from a related Support Center thread

"Hi, I have an application with several workflows that work ok in my local computer (testing with few records), but when I deploy the workflows to a server and the workflow gets approximately 1,500,000 records that match the criteria the workflow service crashes...
I've done some testing and this only happens when the workflow needs to deal with a lot of data, workflows that deal with less records don't have a problem. I've been looking for an alternative like XPCursor or something similar to ask the workflow to page the records that meet the criteria but I haven't found any."


After some time, we could replicate this behavior locally and found that it could be easily improved upon on our side. In short, our solution is in using XafDataView + a sort of paging  when first querying and processing records that match a certain workflow activity definition criteria in the workflow service. 

Thursday, July 23, 2015

Making the AuditTrail functionality operate correctly with several XPObjectSpaceProviders when storing data in separate databases (15.1.6)

I wanted to inform the community of a solution we have just finished testing for the next XAF version in response to the following customer's business scenario:

"i followed this instruction to work with two databases in one application. so far so good. 
i also managed to include the security module and get it working, but now i don't know how to use the "audit trail" module! it doesn't seem to matter in which project i include it, but it will not save anything to the database."


As you probably know, XAF supports connecting to several databases and even using both Entity Framework (EF) and eXpress Persistent Objects (XPO) at the same time (examples: onetwothree), although it is not the primary scenario, to be honest. 

In short, if you were in need of such a configuration and wanted to have AuditTrail capabilities, it would "just work" starting with v15.1.6. If you feel confident to check technical details on this, see my description in the T263982 - AuditTrail - Ensure support for scenarios with several XPObjectSpaceProviders ticket.
By providing support for this module, we continue working in the direction we took in the past, which I also discussed in the past blog. As always, our team is looking forward to hearing your feedback in this regard.

Wednesday, April 1, 2015

Importing administrative or shared model differences via the application UI is possible in v14.2.7

We continue empowering one of the most popular features among our users, which we backed into the standard framework delivery in the v14.2 major release - Persisting UI Settings in the Database.
At this time, I would like to announce the implementation of the ModelDifferenceDbStore - Make it possible to import shared model differences from the application UI request created based on the great feedback of our users:

The ModelDifferenceViewController now includes the ImportSharedModelDifferenceAction Action.



This Action loads shared model differences created in Visual Studio (the Model.xafml file) to the Shared Model Difference object.

Refer to the eXpressApp Framework > Concepts > Application Model > Model Difference Storages documentation to learn more on this cool stuff. 

Thursday, March 19, 2015

Making sure a property value is unique with XAF and XPO

I wanted to share a link to a hot Support Center discussion on the subject (it has now been unpublished by the author, sorry) with the community members as I believe this business task is not unique:-) and many others should be interested in knowing how to properly handle this.
I am going to detail technical considerations of possible solutions at the application UI and database levels depending on various configurations of your data model including inheritance mapping options (Table per Hierarchy or Table per Type) and soft deletion.

Application UI level

First of all, let's start from the UI part. How would a developer of an XAF app ensure that its end-users are not allowed to save records whose property value or combination of values are unique? 
As you know, XAF ships with a built-in validation module that provides a powerful and extendable validation engine and a large set of predefined attributes to configure common validation rules declaratively. To ensure uniqueness, you can first add the ValidationModule component into your XAF module or application via the designers and then choose from the two built-in rules: RuleCombinationOfPropertiesIsUnique and RuleUniqueValue (it is also possible to turn RuleObjectExists and RuleFromBoolPropert for the same task, but its use is not that straightforward use and I will not talk about it for now). Depending on your preferences, you can either annotate your data model classes with the corresponding code attributes, e.g.:

       [RuleUniqueValue]

       public string Name { ... }


or declare everything at the Application Model level via the Model Editor tool (learn more...). In addition, you can configure the rule's CriteriaEvaluationBehavior parameter, to specify whether to look for modified objects that are currently loaded in memory, in addition to objects in the database itself.
As a result, the XAF's validation engine will consider the rules you configured  when a data record is being saved (technically, when the View.ObjectSpace.Committing event is raised) and will throw ValidationException when uniqueness is violated. This is a special exception type, which is caught by other system controllers to display the validation error in a nice way in the UI:




This would be our topmost  or basic protection level as it handles user input only. It will not help avoid duplicates if the same data records are created in code by a developer who did not call one of the Validator.RuleSet.ValidateXXX methods. 

Thursday, March 12, 2015

How to map ORM data model to another schema, e.g. other than the default "dbo" in MS SQL Server?

I just wanted to bring your attention to the recent update of one of the articles in our support knowledge, which is devoted to advanced data layer customizations - telling XAF business objects to use a different owner schema in the database.



Here we go:

Tuesday, February 3, 2015

Storing security settings (users, roles, permissions) and application-specific data in separate databases

I wanted to inform the community of a solution we have just finished testing for the next XAF version in response to the following customer's business scenario:

"We have 2 content databases and we will be running multiple applications on the same databases. Therefore i would like to have a separate database for each application to store the application specific data in...For security reasons we are not allowed to store security data in the same DB as our other data. It not our choice."




Wednesday, January 21, 2015

Simplifying integration of custom controls bound to data from XAF application database - YOUR FEEDBACK IS NEEDED

Scenario


We are researching options to make it easier for our users to achieve the subject in the next version. One of the popular scenarios we were aware of from our users was integration of custom controls, often created in Visual Studio using the standard WinForms or ASP.NET WebForms approaches, and primarily designed for presenting data from the XAF application database in some very custom manner so that built-in XAF Property Editors  or List Editors were not good for this. For instance, you might want to show a list of records in a fancy grid with cards, image gallery or other controls or modes not integrated by default.




Current solutions and problems

XAF is very extensible framework and offers many ways of integrating custom or third party controls. We noticed that while doing so, feeding these custom controls with data from the application database was often a challenge for our users. This binding is done automatically for built-in forms and data editors, but requires writing some code that will read data via the IObjectSpace.GetObjects<T> method (to respect data security filters) and also listen to the IObjectSpace.Reloaded and other events to handle data updates. Finally, designing a data bound user control in Visual Studio often implies a direct connection to the database or using specialized data sources (e.g., to generate a list of grid columns or pivot fields), which do this for you. The latter forces you to think about obtaining an application connection string at design time, while this dynamic part is changed later in the most cases. Add to this different approaches for Entity Framework and XPO and you will get the whole picture.

New solutions (not yet built-in!)

Briefly, we decided to simplify this scenario. Here are two videos that shows one possible option:

ASP.NET:  http://www.screencast.com/t/OHhcHD9vy

WinForms: http://www.screencast.com/t/8M8K4eskkYO9

How it works?


In short, the proposed flow is as follows:

Thursday, January 8, 2015

Model.XAFML and storing XAF application UI settings in the database

As we are improving our newest "Persisting UI settings in the database" feature (quickly learn more about it from this video or blog), I wanted to pay your attention to the ModelDifferenceDbStore - Always take into account the latest changes made to the Model.XAFML file at design time ticket I created based on the users feedback. Let me quote myself from that thread:
Prerequisites

By default, starting with v14.2, all new XAF WinForms projects will store administrative (Model.XAFML) and user differences in the database tables (ModelDifference and ModelDifferenceAspect). 

This built-in option stems from the How to: Store Model Differences in Database example we had in the past.
This new behavior is plugged-in if the Security System is enabled in the Solution Wizard and is technically done by subscribing to the CreateCustomModelDifferenceStore and CreateCustomUserModelDifferenceStore events within YourSolutionName.Module.Win/Module.xx file. Refer to the eXpressApp Framework > Task-Based Help > How to: Store the Application Model Differences in the Database article for more details.

Problem description
As of v14.2.3, the contents of the Model.XAFML file are once read during the first application run and are stored in the database. Thus, any subsequent changes to the Model.XAFML file during development will not be re-read into the database or ignored. This feature request is for improving the developers' experience when this feature is in use.

Current solutions
Take special note that to start reading subsequent customizations from the Model.XAFML file at every application run as it was in the past, you will need to backup and then drop the existing ModelDifference and ModelDifferenceAspect tables in  your test database on your development machine.

Tuesday, December 30, 2014

About XAF Types Info Subsystem...

I have just closed the DC - Provide support for dynamic members in domain components ticket with two possible solutions (there were some specifics with regard to the late generation of real XPO classes for DC interfaces) and wanted to use this chance to draw your attention to some advanced stuff you may need one day - customizing your data model metadata at runtime via the underlying types info subsystem (ooohhh!)

In short, you may need customizations at this low level when you want to dynamically adjust your ORM data model mappings to the database, add or remove custom members for your data model at runtime (e.g., based on the info stored in the database, XML settings file or any other source) when implementing an app tailored to a specific client/user access rights, etc.

Leaving customizations aside (which is quite rare, to be honest), accessing information about the types (their metadata) registered within the XAF application is really common. For instance:

  • If you want to check what business class this View is for - check the View.ObjectTypeInfo property. 
  • If you want to check the member a PropertyEditor corresponds to - check its PropertyEditor.MemberInfo property.
  • Need to know whether a business class has a certain property? Use the ITypesInfo.FindMember or ITypeInfo.Members APIs.
  • Want to know which code attributes are applied to a class or property?  Call the IBaseInfo.FindAttributes method (check examples here).
  • Want to get/set a class property known only at runtime? Use the IMemberInfo.Get/SetValue methods (see an example in the end of this article - it's like .net reflection, but faster).


Our documentation describes this in several articles here:
eXpressApp Framework > Concepts > Business Model Design > Types Info Subsystem

I have also prepared a small schema to better explain the role this type of info subsystem plays:

As you can see from the schema, this 'types info subsystem' serves as a source for Application Model and thus UI generation. That said, in certain scenarios, you may want to access certain info at a higher level instead of accessing the types info subsystem directly.


If you are anxious to see more advanced XAF stuff today, consider reviewing my previous post at
How to customize the underlying database provider options and data access behavior in XAF.


See Also:
eXpressApp Framework > Concepts > Business Model Design > Data Types Supported by built-in Editors

Friday, December 26, 2014

An Entity Framework version of our XCRM demo

You might have noticed that starting with v14.2 we made an EF-based version of our popular XCRM show-case demo. It is installed at %PUBLIC%\Documents\DevExpress Demos 14.2\Components\eXpressApp Framework\XCRM\ by default.


Data models and DbContext code are located within the XCRM.Module\Data\ folder for you to explore. These data models are built for real and quite complex scenarios, so you can use this as a reference in addition to our two other Entity Framework demos:

  • %PUBLIC%\Documents\DevExpress Demos 14.2\Components\eXpressApp Framework\EFDemoCodeFirst\
  • %PUBLIC%\Documents\DevExpress Demos 14.2\Components\eXpressApp Framework\EFDemoModelFirst\

Thursday, December 25, 2014

Looking for practical experiences with both DevExpress XPO & ADO.NET Entity Framework


----

You know that XAF supports both ORM libraries to almost the same extent, so there is no noticeable difference at the framework level (see 1, 2, 3) that should affect your choice in favor of a certain data access tool. There are, however, some differences between these ORMs in their functionality, usability, history and other factors which may indirectly affect your choice.



We do not provide comparisons of our products with competitors (mainly from an ethical point of view), but I think it would not hurt anyone if there was a list of proven opinions from users who had practical experience with both ORM tools. I already started collecting this list and among differences our users mentioned was, for instance:

Wednesday, August 6, 2014

Forcing Boolean Property Editor to work for a string DB column

The world is not perfect and sometimes we have to deal with legacy data, which is not well organized. For instance, data which is binary by nature can be stored using predefined strings ("T"/"F" or "Y"/"N"):


Correcting data is not often possible, because this data can already be used by other information systems.
As you know, XAF automatically generates editors for data fields in the UI based on the field type in the ORM data model (learn more...), so in this particular case an inappropriate editor (text box) will be used if we leave the default mapping to a string column "as is" - a text box instead of a check box or drop down box with the Yes/No values. In this blog post I will show you several methods on how to work around this situation and have the correct editor in the UI while keeping the underlying data table schema and data unchanged.

Saturday, July 19, 2014

How to customize the underlying database provider options and data access behavior in XAF


I just wanted to repost my recent update to the corresponding article, because this information can interest some advanced XAF users.

IMPORTANT NOTE

This article describes some advanced customization techniques and low-level entities of the framework with regard to data access, which may be required in complex scenarios only.
So, if you just want to change the connection string, e.g. to use the Oracle instead of the Microsoft SQL Server database, then you would better refer to the Connect an XAF Application to a Database Provider article and documentation on your database provider instead. The XAF integration of supported ORM libraries is also described in the Business Model Design section of the framework's documentation.

Introducing IObjectSpaceProvider and IObjectSpace

XAF accesses data from a data store through special abstractions called - IObjectSpaceProvider and IObjectSpace.
The IObjectSpace is an abstraction above the ORM-specific database context (e.g., the DBContext used in Entity Framework or the Session in XPO) allowing you to query or modify data.
The IObjectSpaceProvider is a provider/creator of IObjectSpace entities, which also manages which business types these IObjectSpace are supposed to work with, how to set up the underlying connection to the database, create and update it and other low level data access options.



An XafApplication can use one or several IObjectSpaceProvider objects at the same time, and you can access this information through the XafApplication.ObjectSpaceProvder or XafApplication.ObjectSpaceProviders properties. Check out these help links to learn more on how to plug in custom IObjectSpaceProvider objects a well.

There are several built-in implementations of the IObjectSpaceProvider and IObjectSpace interfaces in our framework, which are usually specific to a target ORM (Entity Framework or XPO). I suggest you check out the source code of the default framework classes to better understand the role of the IObjectSpaceProvider:
...\DevExpress.ExpressApp.Xpo\XPObjectSpaceProvider.cs
...\DevExpress.ExpressApp.EF\EFObjectSpaceProvider.cs