CreateSource<ValueFilter> seems not to handle boolean values correctly

Feb 10, 2015 at 2:07 PM
I want to query for all items which have the TeaserAktiv set to True:
var teaserItemsSource = CreateSource<ValueFilter>();
teaserItemsSource.Attribute = "TeaserAktiv";
teaserItemsSource.Value = "True";
What I get is an exception:

Beim Rendern des Templates ist ein Fehler aufgetreten: System.Exception: Error getting List of Stream. Stream Name: Default DataSource Name: ValueFilter ---> System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. bei ToSic.Eav.DataSources.ValueFilter.<>c__DisplayClass6.<GetEntities>b__1(KeyValuePair2 e) bei System.Linq.Enumerable.<>c__DisplayClassf1.<CombinePredicates>b__e(TSource x) bei System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() bei System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer`1 comparer) bei ToSic.Eav.DataSources.ValueFilter.GetEntities() bei ToSic.Eav.DataSources.DataStream.get_List() --- Ende der internen Ausnahmestapelüberwachung --- bei ToSic.Eav.DataSources.DataStream.get_List() bei ASP._Page_Portals_0_2sxc_bwGallery__Galerie__Teaser__cshtml.Execute() in c:\inetpub\dnn\Portals\0\2sxc\bwTest_testcshtml:Zeile 41. bei System.Web.WebPages.WebPageBase.ExecutePageHierarchy() bei System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) bei ToSic.SexyContent.Engines.RazorEngine.RenderTemplate() bei ToSic.SexyContent.Engines.EngineBase.Render() bei ToSic.SexyContent.SexyViewContentOrApp.ProcessView(PlaceHolder phOutput, Panel pnlError, Panel pnlMessage)

When specifiyng a text property, it works like it should.
Feb 10, 2015 at 2:12 PM
Edited Feb 10, 2015 at 2:20 PM
It seems, that only the property which is set as Title will work.
Feb 11, 2015 at 6:34 AM
I haven't looked into this recently, but from what I remember the filter should work with most things. Of course there are probably some issues with type conversions which we haven't tested. I recommend to review what the ValueFilter data-source does in the code of the EAV project.

I'm guessing that passing in a "1" or something might do the trick.
Feb 11, 2015 at 3:24 PM
It seems not to be related to a boolean type. Even a simple string property, which is not "Title" will throw an exception.
Feb 16, 2015 at 6:24 AM
I have a new guess: could it be that you are not using a type-filter first? because then you would try to filter on all content-items, many of which don't have the field you're filtering for.

So the normal way to do it would be something like
var teaserItemsSource = CreateSource<ValueFilter>(App.Data["MyContentType"]);
teaserItemsSource.Attribute = "TeaserAktiv";
teaserItemsSource.Value = "True";
BTW: if this all fails, please post an issue on github and try to include a sample app or something.

As a workaround you can always just write the query in LINQ - something like (pseudocode)
var MainList = App.Data["MyContentType"];
var found = from x in AsDynamic(MainList)
    where x.TeaserAktiv
    select x;
Feb 16, 2015 at 8:03 AM
My "base" source was by getting CreateSource<EntityTypeFilter>(); with TypeName = "MyContentType";
(The Type "MyContentType" also exists in different Apps with the same name.)
When I cascade the retrieved source with a relationship filter, it works like expected, but not with ValueFilter.
I have also tried to get the base source by App.Data["MyContentType"], which results in the same exception.

When I use linq, the excpetion will tell me, that the "TeaserAktiv" will not exist on the dynamic entity.

As I can live without the filter for now, I will give up on this.
Feb 16, 2015 at 10:37 AM
Ok, sorry about that.

If LiNQ says that it can't find a teaseraktiv, I'm guessing that you have many entities - and some don't have that field. Maybe you added the field later on - and then old entities don't have it yet. Since the LINQ tries to do all in one go, you won't see which one doesn't have the property, you'll just see that it didn't always find it.

Feb 16, 2015 at 10:47 AM
Yes, all fields I want to filter are created later on, after the instance of the type was created.
If what you describe is by design, the ValueFilter will be useless.
As I can't be sure if it will work or not after a type change.

By now I can't even change the default settings of a field, as it seems I have deleted some dependencies and I'm unable to find out which.
When clicking on 'Number', all Items are displayed.
When clicking on 'String', I'm getting a resource not info
Requested URL: /Home/ctl/eavmanagement/mid/577/AppID/9/ManagementMode/NewItem/AttributeSetId/205/keyNumber/355/keyGuid/ /AssignmentObjectTypeId/2/ManagementMode/ContentTypeFields/AttributeSetId/228/CultureDimension/0

I'm driving nuts...
Feb 16, 2015 at 1:45 PM
Good that we cornered the problem. I created an issue for it here

We'll probably implement it so, that all items not having this field will be filtered out (since their non-existant-value doesn't match the condition "true" or whatever).

The new problem you're describing sounds confusing. Want to send me an admin/host link so I can look into it?
Feb 16, 2015 at 4:16 PM
If I add a new field, it should always have the default value. So a boolean is then false, even if the entity was created at a time the field was not created.
So a ValueFilter "NewField" == False should return all already existing items even when the field was never initialized.
Feb 16, 2015 at 4:42 PM
I just looked into it. I believe you probably just changed / enabled a URL provider which is causing some redirects and then fails to work. Could you look into that?

I'm guessing you're loosing some values, parameters or the new, long URL is somehow not processed correctly by DNN. So I think it's a URL problem (in DNN), not 2sxc.
Feb 17, 2015 at 10:17 AM
Edited Feb 17, 2015 at 10:17 AM
It turns out that the problem was the URL encoder in DNN.

As many of you know, the current URL-encoder does various things incorrectly if certain pages are not configured in the site settings. These include the setting for search-results but also user-profile-page.

These issues appear when the server finds a complex URL containing ?param=value&param=value - but in general these should not be rewritten for "internal" dialogs. But if the settings for user-profile-page or search-results are missing, DNN will try to rewrite these admin-URLs and sometimes lose or break parameters. Examples are
  • keyGuid=&... (so a blank value
  • results in /keyguid//... - a rather invalid thing
  • or it results in /keyguid/%20/... - much worse then you get a 404 because IIS assumes it's not even a DNN URL
After fixing these settings in the site settings the problem on the system of @smeyer went away.