Why should I use DataQuery & ObjectQuery ?

Mohamed Rashed asked on December 9, 2015 06:33

I was working with custom table API , and I read some blog posts of how to use DateQuery & ObjectQuery, But I notice that there is no benifit to use these two classes over useing my own ORM or Tiny ORM

In the first I thought that using these two classes will cover some pre & post actions like * Logging * Transaction * Security * Caching

and I surprised That I have to handle all of this myself >> and specially security

So I ask my self why not using something like Dapper.net ORM to manipulate my custom table data. at least I have more features than DataQuery & ObjectQuery

If anybody have experience working with Kentico (Content , Custom) Tables Direct using external ORM.

Recent Answers


Roman Hutnyk answered on December 9, 2015 15:37

DocumentQuery, DataQuyre and ObjectQuery are useful with strongly type objects and they provide you with the LINQ methods you'd get from EF for example. As far as custom table items are not strongly type, you can't really benefit that much from using Queries. However, in my opinion, it is not best practice to mix many different technologies in one project. Kentico gives you tools to work with database and usually they work fine. If you don't like API for custom tables - convert it to custom module, so you'll get strongly type object and use ObjectQuery.

1 votesVote for this answer Mark as a Correct answer

Mohamed Rashed answered on December 9, 2015 18:01

Sometimes you have a requirement to store just a simple structured Data, and we can say Custom tables is the best option for it, and no need to go with the complexity of custom modules, specialty it does not provide ready UI to manage Data like Custom tables.

from the other side I don't know how is the ObjectQuery performance in compare with Simple ORM's

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 9, 2015 18:05

In addition to what Roman has already mentioned, I'd highly recommend AGAINST using another ORM tool. I've worked in several other projects where the previous developer had already done this and it caused a lot of problems when we went to upgrade. Maintenance was a nightmare and not only did we have Kentico related upgrade issues, we had to upgrade the ORM tool as well because there were bugs which were fixed.

Using the OOTB API calls does offer all of your common T-SQL security features, it does not perform any type of permission or access checks, that all depends on your business rules and any other ORM will not have this built in either.

Regarding Custom Tables and your own Page Types, Kentico provides you the code you need to get strongly typed objects in return so there should be no issue with any of this. You can simply copy and paste the code into your project and have access to it as needed.

Regarding the items you were talking about

  • Logging
  • Transaction
  • Security
  • Caching

You can take advantage of all of these features using the OOTB API. Sometimes you need to add another line or two of code but all of them are handled OOTB if you tell your query to use them. Off of top of my head I don't have any code samples but I know there are some out there.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.