November Happy Hour will be moved to Thursday December 5th.

attribute query

Vote:
 

Is there any way to query custom attributes in an extended class?

I have extended the Club module to a new class A, with some extra attributes. When searching for A I use ClubQuery and gets the expected result - as long as I create queries with only Club attributes (Name, Description, etc.). BUT I now want to create a query with a custom attribute that only exists in the extension (A). Of course the following error occurs: "There is no attribute with the name 'attr_location' for the type 'StarCommunity.Modules.Club.Club'." Any ideas how to solve this?

Should I somehow create a custom AQuery, extending ClubQuery? How could I then force it to query type A? Or should I add the attribute to Club and somehow get/set custom attribute in base class of A?

#23358
Sep 03, 2008 16:21
Vote:
 

Hi,

First of all, it is not required to extend the class to have attributes, but if you need a subclass for some other reason, then there is a way to solve this.

Simply make your class A behave as a Club class in the eyes of the framework. Meaning you will have to put attributes on the Club class for them to be available for class A. This will make ClubQuery work also.

There is a .Net attribute you will have to add to class A, with the name EntityTypeOverrideAttribute, like this:

 

[StarCommunity.Core.Modules.EntityTypeOverride(typeof(Club))] public class A : Club {  } 

 

 

#23407
Sep 04, 2008 17:45
Vote:
 

Great! Didn't know about the EntityTypeOverride, it solved everything (altough I had to transfer data from attribut of class A to matching Club attribute).

The reason to extend Club was simply to handle attributes without having to know the attribute name all over the site, like a.Location instead of club.getAttributeValue<string>("attr_location")...

Anyway, thanks a lot - it saved my day :)

#23506
Sep 08, 2008 12:50
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.