Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Complex Linq Queries in RavenDB 4.0

DZone's Guide to

Complex Linq Queries in RavenDB 4.0

RavenDB now brings to you new and useful ways to leverage Linq in order to issue queries. Interested? Read on for the details!

· Database Zone
Free Resource

Running out of memory? Learn how Redis Enterprise enables large dataset analysis with the highest throughput and lowest latency while reducing costs over 75%! 

With RQL in RavenDB 4.0, we have a whole new set of capabilities during queries. In the RC1 release of RavenDB, we had limited support for expressing the more complex queries in a strongly typed fashion using Linq. If you needed more complex queries, you had to drop to RQL strings. With the RC2 release, we bring you strongly typed and quite powerful queries using Linq. Let's see how this looks for a very simple query:

Image title

Image title

This isn’t really interesting, but it does show that we can do projections directly from the server side. Let's see something a bit more complex, shall we?

Image title

Image title

This query is more interesting because you can see that we are doing something that you previously had to create a transformer for. We are loading a related document during the query and projecting a field from it back to the user.

In fact, you can even go crazy and define even more complex behavior in the query:

Image title

Image title

In this case, we load two related documents and define a formatting function for names, which we can then apply on two documents.

This kind of code eliminates the need to have transformers entirely, and this makes me very happy.

Running out of memory? Never run out of memory with Redis Enterprise databaseStart your free trial today.

Topics:
database ,ravendb ,linq ,queries

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}