This project is read-only.

Querying non-existent content part also creates it

Topics: Troubleshooting, Writing modules
Sep 15, 2011 at 9:55 PM

Hi all!

I'm pretty sure this is not the intended working: I'm querying for a content part with a specific id:


var item = _contentManager
                .Query<MyItemPart, MyItemPartRecord>()
                .Where(mi => mi.Id == id).List().FirstOrDefault<MyItemPart>();


it (correctly) returns null if no items were found. (I'm not using

var item = _contentManager.Get<MyItemPart>(id);

because it returns an empty, new content part object if none was found.)

So I'm using the first example, but I noticed that later the framework creates the record! (The item variable is not modified in any way, just checked whether it equals null.)

Any ideas to prevent the new record from being created?

Thanks in advance!

Sep 15, 2011 at 10:29 PM

I was wrong. The record was created perhaps because a filter for the User part was added in the handler:

Filters.Add(new ActivatingFilter("User"));

This way when logged in the MyItem was created immediately. But now even if this line is there, I can't reproduce the error.