New Posts New Posts RSS Feed: Access custom properties from EntityAspect
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Access custom properties from EntityAspect

 Post Reply Post Reply
Author
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Topic: Access custom properties from EntityAspect
    Posted: 22-Feb-2013 at 1:48am
Hi,

I've created a custom string property "strFullName" on my entity which basically just returns a concatenated string of several properties such as "strLastName", "strFirstName", and "strMiddleName". I created a generic method that access my entity base, and from here I can only access the EntityAspect property of my entity (not actual field names..). So when I try to access the fields strLastName", "strFirstName", and "strMiddleName", I am able to, but not "strFullName". It throws me an error "DataProperty: 'strFullName' does not exist on type 'EntityAspect'". How can I make it so that I can be able to check the value by using this code?

_currentRecord.EntityAspect.GetDataProperty("strFullName")

(I'm thinking I might need to add some attributes or something on my custom property to make it accessible within the EntityAspect..?)

Thanks,
Von
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 22-Feb-2013 at 10:01am
You can "register" a custom property with DevForce via the PropertyMetadata class and a new DataEntityProperty field, but it may be more work than you want for a simple calculated property. 
 
Registering a backing DataEntityProperty for a custom property looks something like this:
 
public partial class Customer {
  public string FullName {
    get { return PropertyMetadata.FullName.GetValue(this); }
  }
 
  public new partial class EntityPropertyNames  {
    public const string FullName = "FullName";
  }
 
  public partial class PropertyMetadata {
    public static readonly DataEntityProperty<Customer, string> FullName =
    new DataEntityProperty<Customer, string>(
      propertyName: EntityPropertyNames.FullName,
      isNullable: false,
      isPartOfKey: false,
      concurrencyStrategy: ConcurrencyStrategy.None,
      isAutoIncrementing: false,
      relatedNavigationPropertyName: null,
      isNativeProperty: false);
  }
}
 
The problem is that once you've tied into the PropertyMetadata you won't be able to use a simple property getter like you're probably now using, but will need to do some sort of property interception.  Something like this:
 
[AfterGet(EntityPropertyNames.FullName)]
public void FullNameGetInterceptor(PropertyInterceptorArgs<Customer, String> args) {
  args.Value = FirstName + LastName;
}
 
If this all looks like more than you need, then simple reflection will also allow you to get and set your custom property from your entity base class.

 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down