This project is read-only.

AS<T> and Database Access

Topics: Core, Writing modules
Jan 9, 2014 at 2:38 PM
I have a simple question related to As<T>.

I followed the code and realize how it works. My question is, whether there is a DB request every time As<T> is being used?

I read somewhere that using a .Join<T> on the original query to get a certain list of Parts, makes sure that the data is included from the original request and hence no further DB requests are needed.

Jan 9, 2014 at 2:48 PM
Edited Jan 9, 2014 at 2:50 PM
You're right. As<T> won't result in DB roundtrip provided the given part record is already there. Otherwise lazy loading kicks in.

You can force loading specific records by either
  • using .Join<T>. This results in inner join being added to the query.
  • specifying records to load via .WithQueryHints(new QueryHints().ExpandRecords(...)). This will add a left outer join for each of the records specified, thus it won't filter out items that do not have them. Particularly useful when you're querying for items of different types.
Jan 9, 2014 at 3:17 PM

I assume you mean adding the .WithQueryHints(new QueryHints().ExpandRecords(...)) into the contentManager.Query<T,X> correct?

So any query even if using "get" to retrieve a single Content Part, still when we apply As<T> on it inside a View (.cshtml) it will cause another DB request?


BTW, how do you display lines of code inside those white rectangles? Thanks